I am trying to list the execution plan in xml (SET SHOWPLAN ON) of a given sp in a query that returns other things as well. To do that I have been trying to use sp_helptext to return the contents of the given sp in a query but I then want the execution plan of that query itself. Basically I am trying to view all SPs that hit a given index and then list the execution plan for the sp that caused the most load on the server and I am trying to do all of this in one query. I have had some luck pulling the indexes of all the tables out and wrapping that up into an sp itself but I am having trouble pulling out the sp that hits an index the most and showing the execution plan for that sp. Can anyone help me out? Here is what I have so far but I cannot get the second select statement inside of the SP to return anything no matter what I do. I have very little experience with XML and I know that the issue is in the last CROSS APPLY but I cannot for the life of me figure out what it is:
↧