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

extract parameter names and values from a string

$
0
0

Hi - We have a stored procedure log that records the parameters and values for each stored procedure that is executed.  In an effort to make a particular stored procedure run more efficiently, it would be useful to analyze the most commonly used filtering criteria that users plug into the parameters so the sproc's code can be rearranged to improve performance.  The problem is how to extract the parameter names and associated values for further querying.  Here is a sample of data in the log:

Note that the number of parameters in this string is variable, depending upon which sproc is executed.

Here is some code to reproduce the sample data above:

declare @t table (UserID int, SprocID int, Parameters varchar(300), ExecutionDateTime datetime);

insert into @t values
(71, 5270, '@CompanyID=<14> @BeginShipDate=<20130610> @EndShipDate=<20130630> @ShipFromLocation=<5536> @ShipToLocation=<5595> ', '20130607 11:45:14 am'),
(66, 7841, '@FormulaID=<44645> @ManufacturerID=<646> ', '20130608 4:17:28 pm'),
(28, 5270, '@CompanyID=<All> @BeginShipDate=<20130610> @EndShipDate=<20130630> @ShipFromLocation=<All> @ShipToLocation=<All> ', '20130608 5:28:46 pm');

select * from @t;
go

So in this example, the goal is to analyze the parameters for SprocID = 5270.  How can the parameter names and values be extracted for this one sproc so they can be further analyzed?  Keep in mind that in the real life situation there are thousands of entries in the log for analysis.




Viewing all articles
Browse latest Browse all 23857

Trending Articles



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