Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export values of variables from stored procedure

Status
Not open for further replies.

egodette

Technical User
Jun 12, 2002
222
US
I have written a stored procedure and want to export the values of several variables to see what they are durning execution. In VBS I would just use a MSGBOX. This would pause the program and show me the values. How do I do something similiar in MS SQL 2005? Or how do I write the values to a file if that is easire?
 
You can use the Print function. This is what I normally do.

Ex:

Code:
Create Procedure Blah
  @Param1 Int,
  @Param2 VarChar(20)
As
SET NOCOUNT ON

-- Do stuff here

[!]Print @Param1[/!]

-- More Stuff

[!]Print @AnotherVariable

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
And if you need to check the same variable at different places, you can do something like this:
Code:
Create Procedure Blah
  @Param1 Int,
  @Param2 VarChar(20)
As
SET NOCOUNT ON

-- Do stuff here

Print 'First @Param1 value is: ' + CAST(@Param1 AS VARCHAR(20))

-- More Stuff

Print 'Second @Param1 value is: ' + CAST(@Param1 AS VARCHAR(20))

I will do things like that so I can compare what a specific value a variable is at different points in a process.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top