Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to retrieve a data that From substring with a numeric value

ex.

561-265-262665
656-01D-054548
355-2D0-000048
656-656-465656
636-412-112313

on my Query

SQL
SELECT Subtring(BCode,5,3) FROM Table


the result are

265
01D
2D0
656
636

How can I filter for the result of
265
656
636

I've tried REGEX but no luck :(
Posted

 
Share this answer
 
v2
Hi iMaker,


try the below code, It's working for me.

SQL
SELECT SUBSTRING(Column1,5,3) FROM TableName WHERE SUBSTRING(Column1,5,3) not like '%[^0-9]%'


I hope this will help you.

Thank's
Mohan G
 
Share this answer
 
Comments
iMaker.ph 4-Sep-13 2:33am    
It doesn't work :(
anyway thank you :)
Mohan Gopi 4-Sep-13 2:54am    
Hi iMaker, i tried this its working for me. Replace Column1 to BCode and TableName to Table accoding to your query.
iMaker.ph 4-Sep-13 5:53am    
Why is it now working on MySQL? :( anyway I just add a function for this problem.
Hello,

Try bellow query...


Select BCODE FROM
(
Select SUBSTRING(BCode,5,3) as BCODE from Tbl1
)
as
A Where BCODE not like '%[a-z]%'
 
Share this answer
 
Comments
iMaker.ph 4-Sep-13 2:33am    
It doesn't work :(
anyway thank you :)
Just use REGEXP.......


SELECT Substring(BCode,5,3) FROM Table WHERE Substring(BCode,5,3) NOT REGEXP '[[:alpha:]]+'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900