0

I am investigating a single stored procedure that is returning odd results. It dynamically builds sql and uses views and functions. It is difficult to follow what the final sql query applied to the database actually is from the code.

Can I use SQL Server Profiler to see the final query text?

If so, what are the steps? And how do I restrict the Profiler to monitor only a single specific stored procedure?

Gary Barrett
  • 1,764
  • 5
  • 21
  • 33
  • 2
    Yes, you can use SQL Profiler for this, have you reviewed [the documentation](http://msdn.microsoft.com/en-us/library/ms181091(v=sql.100).aspx)? It describes how to run and filter traces, so what exact problem are you having? And if you use a lot of dynamic SQL, it's very useful to add debugging `PRINT` statements to your procedure, perhaps in combination with a [debug parameter](http://stackoverflow.com/questions/10739306/setting-variables-in-sql-functions-probs/10739598#10739598). – Pondlife Oct 26 '12 at 12:57
  • You could also either `PRINT` your dynamic sql or do a `SELECT` of it before executing it – Lamak Oct 26 '12 at 14:12

0 Answers0