June 3, 2015 at 9:42 am
Hello,
I do have table with column A and In column A varchar(100) .. I have value like
Column A
Hello my name is xyz [please tell me your school]
In stored procedure, I would like to return only "please tell me your school".
I would like to pick up string from "[".
Can any one help me to write sql script.
Thanks
LP
June 3, 2015 at 10:05 am
I'm including the code to retrieve the text between [] and avoid rows that won't contain a proper format. Feel free to modify it as needed and ask any questions you have.
DECLARE @String varchar(8000) = 'Hello my name is xyz [please tell me your school]'
SELECT SUBSTRING(@String, CHARINDEX('[', @String) + 1, CHARINDEX(']', @String) - CHARINDEX('[', @String) - 1)
WHERE CHARINDEX('[', @String) < CHARINDEX(']', @String)
AND CHARINDEX('[', @String) > 0
June 3, 2015 at 10:25 am
Thank you so much
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply