How to know which query is resulting in errors in the trace? So, I got this:



A simple trace with user errors.

But, how can I know the query that has the problem listed here?

I don't think DBCC INPUTBUFFER(X) is appropriated to this.

EDIT 1:

Well, I'm using:

STORED PROCEDURES:


RPC: COMPLETED
RPC: STARTING
SP: COMPLETED
SP:STARTED


TSQL:


SQL:StmtCOMPLETED
SQL:StmtSTARTED


And I can see this now:



is there a better approach for this?

I could find the query, because it was the only statement using TOP.I think it was luck.
I would add the events SQL:BatchStarting and/or SP:StmtStarting as well. That way, you can compare the SPID (the session ID) and find which query executed on which SPID.

For the record, Profiler is being replaced by Extended Events (XE for short) as of SQL Server 2008, though the GUI is really only usable as of 2012 in my opinion.