Is it possible to capture the text of an RPC SELECT statement from within the view which it calls? I have tried using dm_exec_cached_plans, dm_exec_query_stats and dm_exec_sql_text but query plans don't seem to be cached until after they are executed. Even dm_exec_query_memory_grants is unavailable until processing is completed.
I need to somehow get the entire query that is currently being executed. I believe dm_exec_requests only returns the current statement, not the full request. Is there some way to tap into sp_prepexec? I am also looking into Extended Events as a possible solution. Is there anything else I can do?
This is SQL Server 2014 -- I posted more details at http://stackoverflow.com/questions/36437573/how-to-get-query-plan-during-execution