Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL Output Message During execution in SSMS

Tags:

sql

sql-server

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?

like image 783
Chris Klepeis Avatar asked Aug 17 '09 13:08

Chris Klepeis


People also ask

How do I display output in SQL Server Management Studio?

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.

How do I print a message in SQL?

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).

How do you display text in SQL?

: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.


1 Answers

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 
like image 151
Mike Forman Avatar answered Oct 10 '22 13:10

Mike Forman