Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


View variable values in SQL stored procedure

View variable values in SQL stored procedure

View variable values in SQL stored procedure

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...

RE: View variable values in SQL stored procedure

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


Select @VariableName

Print @VariableName

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


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".

Microsoft SQL Server MVP
My Blogs
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

RE: View variable values in SQL stored procedure

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.

RE: View variable values in SQL stored procedure

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close