Monday, September 10, 2012

Show me the runtime value

In MSSQL, you may use PRINT statement to display some information when you are executing stored procedure or a SQL batch. This is very helpful to debug the stored procedure which contains many IF statements or you would like to find out the runtime value of certain variable.

For example,

declare @cust_name nvarchar(255)

select @cust_name = cust_name
from tb_customer
where cust_code = 'A001'

print @cust_name

When to use it:
  • Your stored procedure contains many IF statement and you want to know which path has been executed with different parameter value.
  • You want to find out which stored procedure has been called when the main stored procedure has been executed.
  • You want to find out what is the runtime value of the variables.
  • You want to find out where is the process has exited.

No comments:

Post a Comment