现在的位置: 首页 > 综合 > 正文

SQL巧用逗号分隔的字符串实现类似于 where field in (a,b,c,d)的查询

2012年01月01日 ⁄ 综合 ⁄ 共 170字 ⁄ 字号 评论关闭

declare @array nvarchar(100)
set @array='5,100,23,25,7'

select customer_id,customer_name,remarks
from customers
where ','+@array+',' like '%,'+convert(nvarchar(100),customer_id)+',%'

抱歉!评论已关闭.