Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

PRINT statement Expand / Collapse
Author
Message
Posted Wednesday, January 23, 2008 8:15 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Yesterday @ 7:07 AM
Points: 1,478, Visits: 2,101
I have some long-running admin scripts that run every day on some of my servers.

I have several print statments in the job that output status and the results of some of the steps. The PRINT statement doesn't seem to output to the screen (or a log file if run from a job) immediatly. I assume it waits until some buffer somewhere fills up then dumps it.

Question: Is there a way to make it immediatly print when I say print, or am I stuck waiting for SQL to decide when it's ready?



Jason Shadonix
MCTS, SQL 2005
Post #446465
Posted Tuesday, January 13, 2009 7:53 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Yesterday @ 7:07 AM
Points: 1,478, Visits: 2,101
I never did find a way to get the print statement to happen immediatly, but this article tells how to accomplish basically the same thing wiht RAISERROR with the NOWAIT option that I had never thought of:

http://www.mssqltips.com/tip.asp?tip=1660


Jason Shadonix
MCTS, SQL 2005
Post #635430
Posted Tuesday, January 13, 2009 8:50 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 9:45 PM
Points: 36,013, Visits: 30,300
The RAISERROR with the NOWAIT clause is certainly a way to do it... and then, you have nothing but something printed on the screen. No way to do any real analysis... no way to really search for problem points over time.

The best thing to do would be to build a log table and write to the log table instead of writing to the screen. Of course, you should capture the procname with little tricks like OBJECT_NAME(@@PROCID), etc, and maybe even make it so the row identity in the log is remembered so you can log the start and end time of each section of the code instead of having to do a self-join on the log table to find duration. The one I have at work is actually "multi-tiered"... shows start of job and end of job on a job header row. All other rows use that same job header ID to provide a common run (job) reference.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #635513
Posted Tuesday, January 13, 2009 9:07 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Yesterday @ 7:07 AM
Points: 1,478, Visits: 2,101
Agreed.

The cases where I would use that RAISERROR would be when I'm running admin scripts that I only run very infrequently.

I've done similar (though less fancy) things with a log table when I've got scripts that run as part of a scheduled job. That can be very handy if you have lots of exceptions.

Another thing I like to do is specify an output file when I'm setting up job steps. That really helps with troubleshooting if you have your scripts providing good output when failures or exceptions happen.


Jason Shadonix
MCTS, SQL 2005
Post #635547
Posted Tuesday, January 13, 2009 7:42 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 9:45 PM
Points: 36,013, Visits: 30,300
Cool... thanks for the feedback, Jason.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #635960
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse