I have a simple query which loops and I want to see the PRINT messages during the execution. The query is something like this:
WHILE 1 = 1 BEGIN WAITFOR DELAY '000:00:10' PRINT 'here' END
The PRINT 'here'
does not output until I stop the process. However, I want to see it while it's running. Is this possible?
Once we connect to an instance in SSMS, go to View > Output or use the shortcut key (Ctrl+Alt+O). Once you click on Output, it opens up an output window having two drop-down options: Object Explorer.
Declare @SumVal int; Select @SumVal=Sum(Amount) From Expense; Print @SumVal; You can, of course, print any number of fields from the table in this way. Of course, if you want to print all of the results from a query that returns multiple rows, you'd just direct your output appropriately (e.g. to Text).
:Explanation: Note: You can use literal string (enclosed in single or double quotation mark) just like we use a column name in the SELECT statement. If you use the literal string with a column then it will be displayed in every row of the query results.
You can use RAISERROR with serverity 0 and the NOWAIT option
WHILE 1 = 1 BEGIN WAITFOR DELAY '000:00:10' RAISERROR ('here', 0, 1) WITH NOWAIT END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With