怎么样才能实现在select语句中根据传过来字符串循环or?例如:
如果传过来的字符串为a,b,c,d
则显示:select * from tb where id=a or id=b or id=c or id=d
如果传过来的字符串为a,b
则显示:select * from tb where id=a or id=b
如果传过来的字符串为a,b,c,d
则显示:select * from tb where id=a or id=b or id=c or id=d
如果传过来的字符串为a,b
则显示:select * from tb where id=a or id=b
为什么不用
select * from tb where id In(a,b,c,d )呢?
set @s='''a'''+',''b'''+',''c'''+',''d'''
exec('select * from tb where id in ('+@s+')')