Home Forums SQL Server 2005 T-SQL (SS2K5) How to get the actual query text being fired for a particular operation. I'm trying to implement a trigger on a table where i need to store the query also. RE: How to get the actual query text being fired for a particular operation. I'm trying to implement a trigger on a table where i need to store the query also.

  • Thank you for the reply.

    But, can DBCC Inputbuffer(SPID) in an inline query?

    I'm actually trying to monitor the various DML opertaions being performed on a table.

    In the update trigger, i'm capturing all the old values of the columns being updated from the table and along with, host name from which query is fired, sql statement used, updated columns (XML format) etc... into a log table.

    My query is as below:

    INSERT INTO Tablename_Log

    SELECT D.Column1 , D.Column2 , D.Column3 , D.Column4 , D.Column5 ,

    @FldsUpdated, B.Text

    , GetDate(),Host_Name(),A.Session_Id

    FROM DELETED D , (select Session_Id, sql_handle from sys.dm_exec_requests where session_id=@@spid) A

    OUTER APPLY sys.dm_exec_sql_text(A.sql_handle) B

    Thanks And Regards,

    Srinivas