This is something I am just interested in knowing if it is possible.
Could I write an SQL query that could return the text of itself as a variable?
Where I might use this would be on things like reports that I might want to return a variable that saves the actual query that ran to generate the report, or as a debugging tool.
I have seen there is:
that would return the text of the query but can't see an easy way to always get the currently executing queries ID to link back to this table.
Has anyone ever written something to do something like this?
I am using SQL Server 2008, 2012 and 2014.