What SQL Text is that Session Running?

Use the code below if you have a long, complicated, stored procedure or piece of dynamic SQL running on a server, and you’d like to see exactly which piece of SQL Text, or code, is executing.

Not a lot of sql text in this painting.

Not a lot of sql text in this painting.

The output includes the exact statement that is being executed at the time the query runs. The cached execution plan is also shown, if available, along with some other nice details such as the database context, and command type.

This is a lightweight simple piece of code I use when I can’t install Adam Machanic’s sp_whoisactive monitoring system on a server. I’d highly recommend looking at sp_whoisactive since it’s a really thorough and useful utility.

Check out the rest of our tools for SQL Server.