October 23, 2008 at 11:44 am
Hi
I need help: I need to pull the substring which is in single codes (' ') from a long string. How can I do that in SQL server 2000.
e.g: my string is like "iif=(END) condition=() value=('8') trigger=(I)" I need to see only 8 in the result set. This value can be 1-4 digit long.
Thanks
October 23, 2008 at 11:59 am
1. use CharIndex function to find the positions of the single quotes
2. use SubString function and pass in the positions found in step 1 to copy the string inside the quotes.
October 23, 2008 at 12:03 pm
Heh. I used to ask this one in my interview questions:
Declare @str varchar(4000)
Set @str = 'lklkjdflskjflskdjflskdj''1234''s98dfuw8efawufw8uf8'
Declare @Q char(1)
Set @Q = ''''--Apostrophe, or single-quote
Select Substring(@str
, CharIndex(@Q, @str)+1
, CharIndex(@Q, Substring(@str, CharIndex(@Q, @str)+1, Len(@str)))-1)
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply