在某表中有一字段column类型为char,其值为3,4,5
我想让它作为查询条件条件
select * from onttable where temp in (select column from anothertable)
但是sql会将3,4,5看作'3,4,5',把它作为整体,所以查询不出结果。请大家问如何处理。
感谢^_^
我想让它作为查询条件条件
select * from onttable where temp in (select column from anothertable)
但是sql会将3,4,5看作'3,4,5',把它作为整体,所以查询不出结果。请大家问如何处理。
感谢^_^
where a.column = b.column
(
id int identity(1,1),
name varchar(10)
)
insert test select '3,4,5'
union all select 'a'
union all select 'c'
union all select 'b'
union all select 'd'
declare @sql varchar(100)
select @sql=replace(''''+name+'''',',',''',''') from test where id=1
exec('select * from test where id in('+@sql+')')
drop table test
查charindex函数,不清楚哪个放在前面思路就是只要里面包含了就可以,不过必须加',',因为 '3'也是包含在'34'里面的
starsong(流风)
Sorry,不行啊
谢谢大火
---------------------------
'3','4','5'所以可以写成:
select * from onttable where temp in (select ''''+replace(column,',',''',''')+''''
from anothertable)