USE SUSDB; GO SET NOCOUNT ON; DECLARE @MsgStr nvarchar(255); DECLARE @t TABLE (ID INT); DECLARE @command nvarchar(4000); DECLARE @indexid int; SET @MsgStr = 'Loading updates list: ' + convert(nvarchar, getdate(), 121); RAISERROR(@MsgStr, 0, 0) WITH NOWAIT; INSERT INTO @t EXEC spGetObsoleteUpdatesToCleanup; DECLARE cursorIDList CURSOR FOR SELECT * FROM @t; OPEN cursorIDList SET @MsgStr = 'Deleting updates: ' + convert(nvarchar, getdate(), 121); RAISERROR(@MsgStr, 0, 0) WITH NOWAIT; WHILE (1=1) BEGIN FETCH NEXT FROM cursorIDList INTO @indexid; IF @@FETCH_STATUS < 0 BREAK; SET @command = 'exec spDeleteUpdate @localUpdateID=' + cast(@indexid as nvarchar(20)); RAISERROR(@command, 0, 0) WITH NOWAIT; EXEC sp_executesql @command; END -- Close and deallocate the cursor. CLOSE cursorIDList; DEALLOCATE cursorIDList; SET @MsgStr = 'Done deleting updates: ' + convert(nvarchar, getdate(), 121); RAISERROR(@MsgStr, 0, 0) WITH NOWAIT;