日期:2014-05-18  浏览次数:20587 次

关于sql语句 instr 的使用或其他办法?
我有个数据表A 字段 COMP_ID 存储的是 一些公司名的id  
如:(5,12,36,14,23,15,25)

然后我现在想从表 A中 找出 COMP_id 里包含公司ID=5 的那些记录

我曾经想这样 用 

select * from A where instr(cmop_id,5)>0

但是会出现这个问题 (15,25,35)这样的记录也肯定会出来

用 select * from A Where comp_id linke '%5%' 这样 就更不对了

所以不知道还有没有更好的办法

用 where 5 in comp_id 好像还不行 

谁能帮忙

------解决方案--------------------
SQL code

instr这个是你的自定义函数吗?好想SQL Server没有这个函数
SQL Server还可以用charindex(‘5’,cm0p_id)》0来实现

------解决方案--------------------
charindex有试过吗?

select * from A where charindex('5',cmop_id)>0

这个应该行啊
 select * from A Where comp_id like '%5%'//你多写了一个n
------解决方案--------------------
探讨
我有个数据表A 字段 COMP_ID 存储的是 一些公司名的id
如:(5,12,36,14,23,15,25)

然后我现在想从表 A中 找出 COMP_id 里包含公司ID=5 的那些记录

我曾经想这样 用

select * from A where instr(cmop_id,5)>0

但是会出现这个问题 (15,25,35)这样的记录也肯定会出来

用……