Take the 2-minute tour ×

Often I find myself wanting to filter or order the results returned by execing a stored procedure - for example to order the output of sp_who2 by login or CPU Time, or filter it by host name. What is the best way to achieve this?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

One possible solution is to put the result set into a temp table and select from it. Here is an example for sp_who2: SQL Server: Filter output of sp_who2

share|improve this answer
add comment

I love the SMSToolpack. its a free download and lets you sort the resulting grid of any sql query you run.

On top of that, you can search the data just like searching for a text string in excel.

it helps format you SQL text and makes it look pretty so you can be proud of your SQL code and much more...

The best thing i think is it lets you color code windows to specific servers so its simple to know when you are running code on dev vs prod

share|improve this answer
add comment

Your Answer


