How can I get T-SQL PRINT statements to come up in

2019-04-29 01:00发布

问题:

I'm not very experienced with SQL Server Profiler (2005, 2008). I'd like to print some info to a trace from a stored procedure. PRINT statements don't seem to output to my trace. How can I easily get the PRINT statements to output to the trace?

If that's not what trace (or PRINT) is really meant for, what's a quick easy alternative?

回答1:

You could use sp_trace_generateevent to "fire" an event out to your SQL trace. There's an example of it on the BOL page for the proc: http://msdn.microsoft.com/en-us/library/ms177548.aspx



回答2:

Alternatively you can put a print statement into your stored procedure and execute the stored procedure in management studio (exec YourProcedure @Parameter1=10...) and on the messages tab you will see the print statement. If the procedure is running from an application with a lot of parameters you could trace the database to get the exec statement copy it and run it in management studio to see the print statements.