I need help. I want to extract multiple parts of sql statement string. ex. I have the example of string:
UPDATE table SET **XXX** = '1', **YYY** = 2 WHERE ID = 24125;
So, I want to extract these values in bold ('xxx' and 'yyy'. In general, names of columns changed via Update statement.
Here is the example using the substring function, for selecting only one part, but in my case I need multiple parts:
statement like '%UPDATE%' then SUBSTRING(statement,NULLIF(CHARINDEX('SET',statement),0)+LEN('SET')+1, NULLIF(CHARINDEX('=',statement),0) -(NULLIF(CHARINDEX('SET',statement),0)+LEN('SET')+1))
Thank you!
COLUMNS_UPDATED()inside anUPDATEtrigger. But where are you getting theUPDATEstatements themselves from? Are these historic queries? If so usingC#or similar will likely be much more productive than trying to do it in TSQL. For example see stackoverflow.com/questions/5792507/…