sqlserver 将店铺表转换成可以用in查询的字符串

create TABLE #tempshopt (
shopid varchar(max)
)

set @aSql = 'insert into #tempshopt(shopid) select shopid from s_shopid
where shopid in ('+@shop+') and n_leix in (4,5) '
exec(@aSql)

select @shop=''''+SUBSTRING(shopid,3,LEN(shopid)-2)+'''' from (
SELECT distinct (STUFF(( SELECT ''',''' + shopid from #tempshopt a
FOR XML PATH('')), 1, 1, '') ) as shopid FROM #tempshopt AS Test) a

posted on 2019-11-06 09:12  岁月寒风  阅读(678)  评论(0编辑  收藏  举报

导航