Wednesday, 29 November 2017

How to extract a string in between the characters from the string SQL?

Please check with this code, I was used in my project for extracting numeric value
Declare @str varchar(50)= 'userid7f(203001)31f469-NAIsasdsd'
select substring(@str,patindex('%(%',@str)+1,patindex('%)%',@str)-patindex('%(%',@str)-1)
OR
select substring(@str,charindex('(',@str)+1,charindex(')',@str)-charindex('(',@str)-1)
OUTPUT= '203001'

No comments:

Post a Comment