Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Select Multiple Parts of string!

Author  Topic 

asterix5
Starting Member

6 Posts

Posted - 2011-05-02 : 10:12:02
Hello,

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, YYY). In general, names of columns changed via Update statement.

Thank you!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-05-02 : 10:19:39
Read about UPDATE function in SQL Server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

asterix5
Starting Member

6 Posts

Posted - 2011-05-02 : 11:13:17
quote:
Originally posted by madhivanan

Read about UPDATE function in SQL Server help file

Madhivanan

Failing to plan is Planning to fail



I am using currently the SUBSTRING function.
For example, I can select only one part from that string above, let say between "SET" and "=" parts.

SUBSTRING(statement,NULLIF(CHARINDEX('SET',statement),0)+LEN('SET')+0,
NULLIF(CHARINDEX('=',statement),0)-(NULLIF(CHARINDEX('SET',statement),0)+LEN('SET')+0))

But, in my case I need multiple parts.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-05-06 : 08:56:22
It is better to do it vai a trigger using UPDATE() function. If you want to do this in application, split the string by comma and again split the result by =

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -