March 19, 2012 at 1:09 pm
Hello,
This is a simple example of a much more complicated string, but if I have the following SQL
SELECT '/ACLNSTUWX'
IS there a way I can replicate the replace function using SQL regular expressions? I know in some languages they are able to search and replace.
What I want is for each occurrence of / and L to swap to 1, while the others
C, N, S, T, U, W and X
are swapped for 0
Can this be done?
Please bare in mind although my string above is quite simple a more complete string might be
/////AL//////NU/////W//////////
You have to assume the string will be random.
Thanks
March 19, 2012 at 1:33 pm
You mentioned "REPLACE" about 10 times in your post. You can use nested replace like this.
SELECT replace(replace(replace(replace(replace(replace(replace(replace('/ACLNSTUWX', '/', 'L'), 'C', '0'), 'N', '0'), 'S', '0'), 'T', '0'), 'U', '0'), 'W', '0'), 'X', '0')
At least I think that is what you are asking.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply