To view "recent expensive queries" I use Activity Monitor. Some of the queries there are with parameters.

Is there a way to know the values?


Is there a way to know the values?

No, not directly from the Activity Monitor.

You would need to capture those details either using a server-side trace, or using Extended Events.

See the details on this question and the answers for details about how to create a trace to collect that data.

| improve this answer | |
  • thanks, how would I go about creating a server side trace? – user5495269 Nov 13 '15 at 21:00
  • I edited my question with a link that shows how to create the trace. – Max Vernon Nov 13 '15 at 21:53

You can right-click the query you are interested in and select Show execution plan: enter image description here

Once you have the execution plan open, just right-click in an empty area and select Show Execution Plan XML.... Once you have that you will see a section in the XML <ParameterList>. In that node it will show you the ParameterCompiledValue:

      <ColumnReference Column="@records" ParameterCompiledValue="(0)" />
      <ColumnReference Column="@traceid" ParameterCompiledValue="(2)" />

Another way would be to copy the execution plan XML out and paste it into Plan Explorer and view the Parameters tab: enter image description here

Edit for the nerds

If you open up Activity Monitor, and then go into tempdb you will find all the temp objects (tables and all) that Activity Monitor is using. For the Expensive Queries it is using the object dbo.#am_get_querystats. You can open that procedure up and look at the exact query they use to pull it. Pretty cool. I did this for the activity section so I could get similar information without having to open up Activity Monitor all the time.

| improve this answer | |
  • 3
    Shawn, are you sure those are the values used at run time? I think they are the compile-time values. – Max Vernon Nov 13 '15 at 21:09
  • @MaxVernon Not sure what the difference between "run-time" and "compile-time" variables is in the context of SQL stored procedures, but this method shows me the values being used by the instance of the expensive query in the Activity Monitor window. – Dan Nov 10 '16 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.