Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql skip rows that contains string

Hi I need to skip rows that may contain text

Example: I have table OUTSTANDING and my fields are given below.

INVOICENO 
AB1       
111
ZX3

I need to skip rows contain AB1 and ZX3 and select the row that contain 111

I have tried this query

"SELECT * FROM [INT]..OUTSTANDING WHERE INVOICENO NOT LIKE '%[a-z,-]%'";
like image 757
Rakesh Avatar asked Nov 01 '22 06:11

Rakesh


2 Answers

Select *
FROM [INT]..OUTSTANDING 
WHERE IsNumeric(INVOICENO ) = 1 
And INVOICENO Is Not NULL
like image 160
Nelly Avatar answered Nov 15 '22 04:11

Nelly


try with:

"SELECT * FROM [INT]..OUTSTANDING WHERE NOT INVOICENO LIKE '%[0-9]%'";

or

...where INVOICENO not like '%[a-z]%'

unless more advanced regex is required....
source: http://www.sqllion.com/2010/12/pattern-matching-regex-in-t-sql/

like image 43
Milen Avatar answered Nov 15 '22 05:11

Milen