Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Parsing results from sys.dm_exec_sql_text

$
0
0

There may not be a solution to this, but I was hoping that better minds than mine would have a clue:

Create a table Customer:

create table Customer ([ID] [int] IDENTITY(1,1) NOT NULL,
Name varchar(50),Address varchar(50));

Now populate it with a couple of rows. Next create a View that includes the batch:

create view Customer_view (id, name, address, Text) 
as  Select id, Name, Address, Text from Customer,
sys.dm_exec_sql_Text((Select sql_handle from sys.sysprocesses where spid = @@spid))

Finally, issue this query:

Select Name,Text from Customer_View where id = 1;
Select Address,Text from Customer_View where id = 1;
go

You will notice that the Text from both Selects is the same, i.e., the full batch:

"Select Name,Text from Customer_View where id = 1; Select Address,Text from Customer_View where id = 1;"

Is there a way to parse the output Text so that it only includes the Text for the specific Select statement. So for example, the Text from the first Select would contain only this:

"Select Name,Text from Customer_View where id = 1;"

and the Text from the second Select would contain only this:

"Select Address,Text from Customer_View where id = 1;"



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>