sql跳过包含字符串的行

时间:2014-01-28 10:22:08

标签: sql sql-server tsql

您好我需要跳过可能包含文字的行

示例:我有表OUTSTANDING,我的字段在下面给出。

INVOICENO 
AB1       
111
ZX3

我需要跳过包含AB1ZX3的行,并选择包含111的行

我试过这个查询

"SELECT * FROM [INT]..OUTSTANDING WHERE INVOICENO NOT LIKE '%[a-z,-]%'";

4 个答案:

答案 0 :(得分:1)

尝试:

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

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

除非需要更高级的正则表达式....
来源:http://www.sqllion.com/2010/12/pattern-matching-regex-in-t-sql/

答案 1 :(得分:1)

Select *
FROM [INT]..OUTSTANDING 
WHERE IsNumeric(INVOICENO ) = 1 
And INVOICENO Is Not NULL

答案 2 :(得分:0)

答案 3 :(得分:0)

尝试以下方法:

方法1:

SELECT * 
FROM [INT]..OUTSTANDING
WHERE InvoiceNo IS NOT NULL
    AND ISNUMERIC(InvoiceNo)=1

方法2:

SELECT * 
FROM [INT]..OUTSTANDING 
WHERE InvoiceNo IS NOT NULL
  AND INVOICENO NOT LIKE '%[^0-9]%'