为什么通配符无法在SQL Server 2008中用于Range [英] Why Wildcard not working in SQL server 2008 for Range

查看:105
本文介绍了为什么通配符无法在SQL Server 2008中用于Range的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的代码为

声明@phone varchar(10)
set @ phone ='01234567891'
if @phone like' %[^ 0-9 {1,9}]%'
打印'Y'
其他
打印'N'



我希望根据通配符只允许1到9范围内的值,但它不起作用的原因?

解决方案

 声明  @ vchar   varchar  50 
set @ vchar = ' 0124667891';
选择 案例 何时 < span class =code-sdkkeyword> @ vchar 喜欢 ' %[^ 0-9]%' 然后 ' Number' else ' 不是数字' 结束


I have written the code as

declare @phone varchar(10)
set @phone='01234567891'
if @phone like '%[^0-9{1,9}]%'
print 'Y'
else 
print 'N'


where i want to allowed only value in range of 1 to 9 as per the wildcard but its not working why?

解决方案

declare @vchar varchar(50)
set @vchar ='0124667891';
select case when @vchar not like '%[^0-9]%' then 'Number' else 'Not a Number' end


这篇关于为什么通配符无法在SQL Server 2008中用于Range的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆