教程学院
图像设计 多媒体类 机械制图 办公软件 操作系统 系统编程 网站编程 网页制作 数据库类 网络路由 网络工程 网络安全 考试认证
firefox火狐浏览器下载
酷网学院
CAD
AutoCad Cam350 ProEngineer GCcam MATLAB Unigraphics SolidWorks CAXA Solid3000 Cimatron EdgeCAM
系统
安全 防火墙 病毒 WinXP Win2003 Vista
数据库
编程
网络
精彩图库
  当前位置: 库库中文网 · 数据库类教程 · MSSQL教程 · MsSql综合技巧

字符串地查询疑难

学院最新推荐文章
教程推荐
『字符串地查询疑难』如果文章有大量图片,显示会较慢,请等待图片下载完成
 
点击数: 更新时间:2008-9-28 
从一个个长度为7位的字符串列中查询满足以下条件的记录:第1位 = 2 or * ,第2位 = 3 or * ,第3位 = 8 or * ,第4位 = 5 or * ,第5位 = 9 or * ,第6位 = 7 or * ,第7位 = 4 or *

怎么能用简单方法实现,即不通过一个个字符比较来实现。

这个问题第1个回答:
SQL code

select col from tb where substring(col,1,1) in(1,'*') and substring(col,2,1) in(3,'*') and

substring(col,3,1) in(8,'*') and substring(col,4,1) in(5,'*') and substring(col,5,1) in(9,'*')

and substring(col,6,1) in(7,'*') and substring(col,7,1) in(4,'*')


这个问题第2个回答:
把所有可能存一个表中?

这个问题第3个回答:

不是很明白 LZ的意思。。。
这个问题第4个回答:
SQL code

declare @t table(col varchar(10))

insert @t select '2**5974'

insert @t select '*3**9**'

insert @t select '2*2597s'

select col from @t where substring(col,1,1) in(2,'*') and substring(col,2,1) in(3,'*') and

substring(col,3,1) in(8,'*') and substring(col,4,1) in(5,'*') and substring(col,5,1) in(9,'*')

and substring(col,6,1) in(7,'*') and substring(col,7,1) in(4,'*')



/*

col        

---------- 

2**5974

*3**9**

*/


这个问题第5个回答:
kankan
这个问题第6个回答:
SQL code

declare @t table(col varchar(10))

insert @t select '2**5974'

insert @t select '*3**9**'

insert @t select '2*2597s'

select col 

from @t 

where col like '[2*][3*][8*][5*][9*][7*][4*]'





/*

col

----------

2**5974

*3**9**



(2 行受影响)

*/


这个问题第7个回答:
引用 6 楼 happyflystone 的回复:
SQL code
declare @t table(col varchar(10))
insert @t select '2**5974'
insert @t select '*3**9**'
insert @t select '2*2597s'
select col
from @t
where col like '[2*][3*][8*][5*][9*][7*][4*]'

/*
col
----------
2**5974
*3**9**

(2 行受影响)
*/

支持!
这个问题第8个回答:
呵呵,tim_spac 好厉害
这个问题第9个回答:
引用 6 楼 happyflystone 的回复:
SQL codedeclare @t table(col varchar(10))
insert @t select '2**5974'
insert @t select '*3**9**'
insert @t select '2*2597s'
select col
from @t
where col like '[2*][3*][8*][5*][9*][7*][4*]'


/*
col
----------
2**5974
*3**9**

(2 行受影响)
*/

作者:lyyrw 来源:C.S.D.N
】【关闭窗口
·上页:
·下页:
相关文章
     数据库类教程 - MsSql综合技巧
普通教程【脑袋快想爆炸了- -!】 怎么样
普通教程关于级联删除地疑难,新手提问,
普通教程怎么样动态控制列数?
普通教程数据库恢复 MS2000
普通教程当数据库中varchar字段值为null
普通教程create function 怎么才无法要返
普通教程各位帮我看看是啥疑难啊, SQL运
普通教程SQL server 2005 安装疑难 SP2更
普通教程sql update
普通教程update触发器地疑难
普通教程字符串地查询疑难
普通教程安全性--登陆--想建一个用户tes
精彩图片汇集
advertisement
关于站点 - 广告服务 - 联系我们 - 版权隐私 - 免责声明 - 合作伙伴 - 程序支持 - 网站地图 - 返回顶部
网站文本地图
版权所有:库库中文 2005-2007 欢迎各种媒体转载我们的原创作品[转载请注明出处]
copyright © 2005-2008 www.QQGB.com online services. all rights reserved. 蜀ICP备05015578
Template designed by Virus. Optimized for 1024x768 to Firefox,Opera and MS-IE6. Site powered by EQL.
红盾
热爱电脑,热爱生活
拥有电脑,拥有生命
让我们享受拥有电脑的时光