Hi,
I use PRINT statements to display final message in my stored procedure. Is any way to catch PRINT output (it is Messages in SSMS)? I need to send email if SP returns any messages once it finishes.
Thanks
Technology Tips and News
Hi,
I use PRINT statements to display final message in my stored procedure. Is any way to catch PRINT output (it is Messages in SSMS)? I need to send email if SP returns any messages once it finishes.
Thanks
You can only catch automatically if SQLCMD is used for the script execution (-i and -o parameters).
SQLCMD: https://msdn.microsoft.com/en-us/library/ms162773.aspx
PRINT is the not way to accomplish what you are looking for, you need to use RAISERROR.
Please see:
https://msdn.microsoft.com/en-us/library/ms178592.aspx?f=255&MSPPError=-2147217396
Hi Jori5,
Usually the Message pane in SSMS shows the rows that affected by the statments and syntax or runtime error message.
May I know what kind of message is your Stored Procedure(SP) expected to return?
For the affected rows, the message can be avoided by "SET NOCOUNT ON" or be captured by "SELECT @@ROWCOUNT".
For the error message, it can be captured by "SELECT
@@ERROR", see more about
Error Handling in SQL Server.
If what you'd like to capture is only the message in your own PRINT statements, you can follow the advice in above posts to declare an OUTPUT parameter and assign your final message to the parameter. see below link.
Returning Data by Using OUTPUT Parameters
If you have any question, feel free to let me