Wednesday, 29 November 2017

How to get the only numeric part from a string SQL?

How to get the only numeric part from a string SQL?
Please check with this code, I was used in my project for extracting numeric value
DECLARE @string varchar(100)
SET @string = 'sk123;fja4567afj;as8901sfsfsfa2'
WHILE PATINDEX('%[^0-9]%',@string) <> 0
SET @string = STUFF(@string,PATINDEX('%[^0-9]%',@string),1,'')
SELECT @string
OUTPUT= '123456789012'

No comments:

Post a Comment