Looks like good info to have. . ., but my SSMS query keeps rejecting the code. It complains about the three inline queries for the elements from dm_exec_sql_text function, doesn't like the '.' within the function argument. Is this a database compatibility issue?

I was testing your script so just want to make sure little thing in result set session_id is the SPID right?is there possibility with this script can show up the date and time of user . like what time they ran any query?Thanks