user3782584
user3782584

Reputation: 11

Extracting numeric part from string - SYBASE ASE

I am trying to extract the 7658 from string [email protected]. 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('[email protected]', PATINDEX('%[0-9]%', '[email protected]'),   
       LEN('[email protected]')) as number

Go

 Number
 --------------
 [email protected] 

Upvotes: 0

Views: 2350

Answers (1)

Meet
Meet

Reputation: 418

You did not mention the end poistion

DECLARE @str VARCHAR(100)
SELECT  @str='[email protected]'

SELECT  SUBSTRING(@str, PATINDEX('%[^0-9][0-9]%', @str) + 1, PATINDEX('%[0-9][^0-9]%', @str) - PATINDEX('%[^0-9][0-9]%', @str))

Upvotes: 2

Related Questions