I can use the PRINT statement in a stored procedure to debug my code. I see the output in the Messages tab of SQL Server Management Studio. How can I dump one or more entire SELECT statement outputs to that Messages tab?
My stored procedure returns several output variables so returning a single dataset isn’t an option here. I am struggling with finding a good way to debug my complex procedures.
Getting the entire contents of a query to print to the messages window would probably be more trouble than it’s worth. Instead, I would recommend debugging the procedure from a query window. What you can do is add an optional parameter to your procedure, with a default of NULL. Your app won’t be passing it, so you can use this to your advantage. Ex:
Then, when you call this procedure from a query window, simply pass in a value of 1 to the procedure for that @Debug parameter