Use the code below to get the spid and then you can filter it in the SQL Profiler.
http://www.sqlservercentral.com/scripts/Connections/86792/
For selecting events:
https://msdn.microsoft.com/en-us/library/ff650699.aspx
To identify a long-running query interactively
- Start SQL Profiler.
- On the File menu, click New, and then click Trace.
- Specify the relevant connection details to connect to the computer running SQL Server.
The Trace Properties dialog box appears.
- In the Template name list, click SQLProfilerTSQL_Duration.
- Click the Events tab.
Notice that two key events are selected:
- RPC:Completed from the Stored Procedures event class
- SQL:BatchCompleted from the T-SQL event class
- Click Run to run the trace.
- Start SQL Query Analyzer.
- Run the queries you want to analyze. For example, using the Pubs database, you might run the following query.
select au_id, au_lname + ' ' + au_fname, phone from authors where au_lname like 'G%' order by au_lname
select * from authors
Select au_id from authors
- View the trace output in SQL Profiler. Note that durations are given in milliseconds.
Figure 1 shows sample output.
Figure 1: Sample SQL Profiler output using the SQLProfilerTSQL_Duration template
- Stop the trace.
Note Your duration times may vary from those shown, and may even appear as zero if the database server has a small load.