比如 like '[0-9][0-9]....' 也行 , 但是我如果有100 个数字, 要写100 个, 其他方法? 另外, _ 是否属于 SARG 呢, 好像还是 index scan ....
如果使用 like '[0-9][0-9]..... ' 也行, 但是 如果我有 100 个数字, 要写100个, 其他方法???另外 _ 是否 属于SARG 呢? 好像还是 index scan ....
这个无法替代。 有时候要看你这列具体的数据来看有没有变通成属于SARG的写法。
try: Declare @1 Table(x nvarchar(20))Insert Into @1 Select N'1232432as23421232' Union All Select N'5676523123' Union All Select N'4534sdxc@323' Union All Select N'(323dsd' Union All Select N'sdf2324324' Union All Select N'sdfdsd' Union All Select N'45434345' Select x from @1 Select x from @1 Where Patindex('%[^1-9]%',Left(x,5))=0 --查询前五位都是数字的行数据 /* x -------------------- 1232432as23421232 5676523123 4534sdxc@323 (323dsd sdf2324324 sdfdsd 45434345x -------------------- 1232432as23421232 5676523123 45434345 */
纠正下 Where Patindex('%[^1-9]%',Left(x,5))=0 --查询前五位都是数字的行数据 应该是 Where Patindex('%[^0-9]%',Left(x,5))=0 --查询前五位都是数字的行数据因为0也是数字o(∩_∩)o...
16个 _
每个 _ 代表一个字符长度的任意字符
也行 , 但是我如果有100 个数字, 要写100 个,
其他方法? 另外, _ 是否属于 SARG 呢, 好像还是 index scan ....
有时候要看你这列具体的数据来看有没有变通成属于SARG的写法。
Declare @1 Table(x nvarchar(20))Insert Into @1
Select N'1232432as23421232' Union All
Select N'5676523123' Union All
Select N'4534sdxc@323' Union All
Select N'(323dsd' Union All
Select N'sdf2324324' Union All
Select N'sdfdsd' Union All
Select N'45434345' Select x from @1
Select x from @1
Where Patindex('%[^1-9]%',Left(x,5))=0 --查询前五位都是数字的行数据
/*
x
--------------------
1232432as23421232
5676523123
4534sdxc@323
(323dsd
sdf2324324
sdfdsd
45434345x
--------------------
1232432as23421232
5676523123
45434345
*/
Where Patindex('%[^1-9]%',Left(x,5))=0 --查询前五位都是数字的行数据
应该是
Where Patindex('%[^0-9]%',Left(x,5))=0 --查询前五位都是数字的行数据因为0也是数字o(∩_∩)o...