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!

View variable values in SQL stored procedure 2

Status
Not open for further replies.

Webkins

Programmer
Dec 11, 2008
118
US
Hello, I have a stored procedure in SQL2K which contains many @variables. I would like to debug my stored procedure and see the actual contents of each variable. Is it possible to step through the code or to see the contents of each variable similar as in VB/VBA ?

Thank you...
 
I've never really had much luck debugging/stepping through TSQL code. Instead, I usually print or select the variables, like this....


Code:
Select @VariableName

Print @VariableName

You can even hard code values so you can check the variable values at different points within the code. Ex:

Code:
Select 'Before Query 1',@Variable

-- Big ole query here

Select 'After Query 1',@Variable

Of course, you'll need to remove (or comment) these lines prior to declaring your code "done".

-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
 
As per my comment in your other thread, this is why I would leave logic handling in a higher level application level and leave stored procedures for simply retrieving the data you need.
 
There is a debugger you can step through code with and see variables but it can be a pain to set up. To me it was worth the effort. I had to coordinate setting it up with the DBA group (I'm in applications). It's been quite a while but this link jogged my memory on some of the thinks we needed to do.


Then MS took it away in 2005 and I believe it is coming back in 2008. MS VS 2010 has a stored procedure debuuger that is pretty cool and I believe the software is free.

In all the scenarios the DBA group here keeps it in the deveopement environment becuase of the access needed to run them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top