How to use the PRINT statement to track execution as stored procedure is running?
sql-server, t-sql
Solution
I'm sure you can use RAISERROR ... WITH NOWAIT
If you use severity 10 it's not an error. This also provides some handy formatting eg %s, %i and you can use state too to track where you are.
Problem
Reference: SQL Server I have a stored procedure with a `while` loop in it and I want some messages to be printed after every 500 loops. So, I've written - ``` CREATE spxxx AS BEGIN BEGIN TRAN DECLARE @counter = 0; WHILE <somecondition> SET @counter = @counter + 1; IF @counter % 50 = 0 BEGIN PRINT @counter; END END COMMIT TRAN END -- End spxxx ``` But it prints all the messages once the proc ends. I want it to print the messages while its running.