0

I am trying to extract the 7658 from string XYZ.ABC7658@YAHOO.CO.IN. Below is the query which I am trying and the output is also shown. However the query doesn't server the purpose.

Can you please help on this? (Running Query on Sybase ASE)

SELECT SUBSTRING('XYZ.ABC7658@YAHOO.CO.IN', PATINDEX('%[0-9]%', 'XYZ.ABC7658@YAHOO.CO.IN'),   
       LEN('XYZ.ABC7658@YAHOO.CO.IN')) as number

Go

 Number
 --------------
 85@YAHOO.CO.IN 
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115

1 Answers1

2

You did not mention the end poistion

DECLARE @str VARCHAR(100)
SELECT  @str='XYZ.ABC7658@YAHOO.CO.IN'

SELECT  SUBSTRING(@str, PATINDEX('%[^0-9][0-9]%', @str) + 1, PATINDEX('%[0-9][^0-9]%', @str) - PATINDEX('%[^0-9][0-9]%', @str))
Meet
  • 408
  • 2
  • 10