22,209
社区成员
发帖
与我相关
我的任务
分享
--楼主可以直接运行
declare @orderInfo table (orderNum varchar(1),Product varchar(5))
insert into @orderInfo
select 'a','商品1' union all
select 'b','商品2'
declare @ExpressOrder table (ID int,orderList varchar(6))
insert into @ExpressOrder
select 1,'a,b'
select a.ID,orderNum ,product,orderNum from @ExpressOrder a
right join @orderInfo b
on charindex(','+b.orderNum+',',','+a.orderList+',')>0
/*
ID orderNum product orderNum
----------- -------- ------- --------
1 a 商品1 a
1 b 商品2 b
*/
selecta.ID,orderNum ,product,orderNum from expressORder a
right join orderInfo b
on charindex(','+b.OraderNum+',',','+a.orderNum+',')>0