I have some stored procedures that i would like to know how gets called. Is it possible to get the query that gets executed from inside the procedure?
EX SELECT PROPERTY('QUERY')
asked 28 May '13, 09:07
You can see the text of stored procedures by viewing the SYS.SYSPROCEDURE system view.
e.g. To see the text for a stored-procedure "sp_targetsp()":
SELECT proc_defn FROM SYS.SYSPROCEDURE WHERE proc_name = 'sp_targetsp'
You may also need to filter by "owner" if there are multiple stored procedures with the same name created by different database users.
If you'd like to see what is being executed inside of a stored procedure at runtime, you can monitor these statements using request-level logging: