当前位置: 代码迷 >> Sql Server >> sql数据问 解决马上给分
  详细解决方案

sql数据问 解决马上给分

热度:26   发布时间:2016-04-27 18:41:38.0
sql数据问在线等 解决马上给分
表 b
id name
1 方正
2 hp
3 tcl

表a

id aname brands
1 电脑 1,2,3
2 IBM电脑 3


知道 b表的一个id 要查这个id 在a表brands
哪几个行出现过并返回这些行 请问怎么做好些 a表的数据比较多 

如果知道 id 92我想把有 92的行查出来结果

select * from a where brand like '%92%'
的话 会把有 921 922 的也查出来 

哪里位大哥帮我解决此问题

------解决方案--------------------
declare @id varchar(10)
set @id='92'

select * from a
where charindex(',[email protected]+',',','+brands+',')>0
------解决方案--------------------
SQL code
select * from a where charindex(',92,', ','+brand+',')>0
------解决方案--------------------
SQL code
select * from a where ','+brand+',' like '%,92,%'
------解决方案--------------------
SQL code
select b.* from b , a where charindex(','+cast(b.id as varchar)+',',','+a.brands+',') > 0
------解决方案--------------------
SQL code
--查全部select b.* from b , a where charindex(','+cast(b.id as varchar)+',',','+a.brands+',') > 0--只查92select b.* from b , a where charindex(',92,',','+a.brands+',') > 0
------解决方案--------------------
漏了
SQL code
select * from a where brand like '%,92,%'    or brand like '92,%'   or brand like '%,92'
  相关解决方案