Using SQL 2008
ID: C/213434343434334, CA/2566121212122
From the above id, i want to take only numbers. How to acheive this
Required Output
213434343434334, 2566121212122
Need Query Help
Using SQL 2008
ID: C/213434343434334, CA/2566121212122
From the above id, i want to take only numbers. How to acheive this
Required Output
213434343434334, 2566121212122
Need Query Help
try this way
DECLARE @str VARCHAR(400)
DECLARE @expres VARCHAR(50) = '%[a-z,/]%'
SET @str = 'CA/2566121212122'
WHILE PATINDEX( @expres, @str ) > 0
SET @str = Replace(REPLACE( @str, SUBSTRING( @str, PATINDEX( @expres, @str ), 1 ),''),'-',' ')
SELECT @str
SELECT substring(ID,charindex('/',ID)+1,len (ID)-charindex('/',ID)) New_Id
FROM [YOUR TABLE]
If all characters will be in front of the special character '/', you can use the following:
DECLARE @ID1 nvarchar(200) = 'C/213434343434334',
@ID2 nvarchar(200) = 'CA/2566121212122'
SELECT RIGHT(@ID1, CHARINDEX('/', REVERSE(@ID1))-1)
SELECT RIGHT(@ID2, CHARINDEX('/', REVERSE(@ID2))-1)
RESULTS:
RESULT @ID1 : 213434343434334
RESULT @ID2 : 2566121212122
Hope this helps
Use SUBSTRING() to get the result.
CREATE TABLE #Test
(
ID NVARCHAR(MAX)
)
INSERT INTO #Test
SELECT 'C/213434343434334' UNION
SELECT 'CA/2566121212122'
SELECT SUBSTRING(ID, CHARINDEX('/', ID)+ 1, LEN(ID)) AS ID FROM #Test