I am no database admin nor is my SQL-foo any good (yet), but have a few tasks to get done in MSSQL, and one is a rather time intensive procedure where I fetch from a
WHILE @@FETCH_STATUS = 0, I have multiple
SELECTs and an
UPDATE on giant tables. (The procedure works, I've checked with a colleague)
Now in a script or a program I'd have a simple print @current_cursor or print a counter in every
WHILE just to have some feedback.
How could I do something like this in MSSQL? (Working on Microsoft SQL Server Enterprise Edition v9.00.3042.00, i.e. SQL Server 2005 Service Pack 2)
Could I do a
print @current_cursor, or would that be a no-go in my case?
I've tested the
RAISEERROR with the following statements:
DECLARE @cur_id int; SET @cur_id = 0; DECLARE Cur CURSOR FOR SELECT ID FROM TableA WHERE ID > 100 ORDER BY ID DESC OPEN Cur FETCH NEXT FROM Cur INTO @cur_id; WHILE @@FETCH_STATUS = 0 BEGIN RAISERROR(@cur_id, 0, 0) WITH NOWAIT FETCH NEXT FROM Cur INTO @cur_id; END
But this leads to some time of waiting without output and then an endless wall of (I assume one for every
Msg 18054, Level 16, State 1, Line 17 Error 983700, severity 0, state 0 was raised, but no message with that error number was found in sys.messages. If error is larger than 50000, make sure the user-defined message is added using sp_addmessage.