|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, May 08, 2012 5:13 AM
Points: 7,
Visits: 77
|
|
Hi All,
Can some one help me in getting the actual query text being used to perform an operation. I'm doing a Outer Apply with sys.dm_exec_sql_text(deqs.sql_handle), though this is giving correct info but not in the desired manner. I'm doing this implementation inside a trigger. In case of a stored proc call which has some internal DML operations in it, i want the query text as "Exec Procname 'xxxx', 'xxxxx'" which is the actual one which is fired. But the DMV which i've specfied above is giving me the entire content of the SP being fired.
Request help to address my issue.
Thanks in advance.
Srinivas
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 1:49 PM
Points: 14,133,
Visits: 8,525
|
|
Is there a reason to do this in a trigger, as opposed to working from a trace? A trace will give you exactly what you're looking for, the proc name and parameter values. What are you doing with the data in the trigger?
- GSquared, RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Tuesday, April 24, 2012 2:52 AM
Points: 509,
Visits: 713
|
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Yesterday @ 10:50 AM
Points: 4,164,
Visits: 8,742
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, May 08, 2012 5:13 AM
Points: 7,
Visits: 77
|
|
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
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Tuesday, April 24, 2012 2:52 AM
Points: 509,
Visits: 713
|
|
sinureddi (1/6/2009)
But, can DBCC Inputbuffer(SPID) in an inline query?
No - it just gives you what was sent to the server - I wasn't 100% sure where you were coming from so thought I would mention it just in case! :D
Atlantis Interactive - SQL Server Tools My blog Why I wrote a sql query analyzer clone
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 1:49 PM
Points: 14,133,
Visits: 8,525
|
|
I don't know a way to get exactly what you're looking for in one solution.
I'd log the update (as you're doing), and run a trace. From time-stamps, SPIDs, etc., you should then be able to join the two together after the fact. Trace will give you exact command run, log will give you the rest of it.
It's not ideal, but it will work.
- GSquared, RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|