• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

SQL Server: how to print during program execution?

Print output appears in Messages window only after all sprocs execution completes. How to see results during execution, not in the end.
0
quasar_ee
Asked:
quasar_ee
2 Solutions
 
prequel_serverCommented:
Not sure I understand what you mean but I usually use GO after each proc block to execute a batch of script at a time
0
 
Deepak ChauhanSQL Server DBACommented:
You can use the "print" keyword like :

declare @min int, @max int , @cmd varchar(20)
set @min =1
set @max=10000000
set @cmd='Current Value is: '
while @min <=@max
begin
print @cmd+cast(@min as varchar)

set @min=@min+1
end
0
 
vinurajrCommented:
you add print statements whenever required
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>How to see results during execution, not in the end.
You'll need to provide us some more details.

I've seen some VERY long SP's where in order to be able to view progress the developers created a cursor where rows were processed 50,000 at a time, and the end of each cursor loop logged a row to a 'logging' table to show the status.  That way, developers can query the table to see the progress of the SP.
0
 
Scott PletcherSenior DBACommented:
quasar:

You're quite right: SSMS buffers PRINT results, so you won't see them immediately; when the buffer fills, it flushes and then  you see the results.  I don't know of a really good way around that, although I've tried to find one.

You could try "RAISERROR('...', 1, 1) WITH NOWAIT", but I've seen that get buffered also.

You could also try PRINTing long dummy strings to fill the buffer, but then you have to read around those when you look at the output.
0
 
Anthony PerkinsCommented:
Good question.  If it is that important to you, your best bet is to use Jim's solution of inserting into a table and polling it frequently.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now