现在我有两张表:表1
订单表有两条记录: orderInfo
orderNum Product
a 商品1
b 商品2运送单有一条记录: ExpressOrderID orderList
1 a,borderNum product ID
a 商品1 1
b 商品2 1selecta.ID,orderNum ,product,orderNum from expressORder a
right join orderInfo b
on b.OraderNum in (a.orderNum)但是这个语句查询出来后没有运送单的ID也就是说查询出的效果为
orderNum product ID
a 商品1 null
b 商品2 null我的sql语句有错么?我想应该是 on b.OraderNum in (a.orderNum) 语句的错误吧!@但是我不知道怎么改,求解惑另外:如果我的orderList字段自由一个orderNum,就是正常的。
订单表有两条记录: orderInfo
orderNum Product
a 商品1
b 商品2运送单有一条记录: ExpressOrderID orderList
1 a,borderNum product ID
a 商品1 1
b 商品2 1selecta.ID,orderNum ,product,orderNum from expressORder a
right join orderInfo b
on b.OraderNum in (a.orderNum)但是这个语句查询出来后没有运送单的ID也就是说查询出的效果为
orderNum product ID
a 商品1 null
b 商品2 null我的sql语句有错么?我想应该是 on b.OraderNum in (a.orderNum) 语句的错误吧!@但是我不知道怎么改,求解惑另外:如果我的orderList字段自由一个orderNum,就是正常的。
from orderInfo a left join ExpressOrder on charindex(','+a.orderNum+',',','+b.orderList+',') > 0
from
(Select
orderNum=substring(a.orderList,b.number,charindex(',',a.orderList+',',b.number)-b.number),ID
from
ExpressOrder a join master..spt_values b
ON B.type='p' AND B.number BETWEEN 1 AND LEN(a.orderList)
where
substring(','+a.orderList,b.number,1)=',')t
left join orderInfo c on t.ordernum=c.ordernum
right join orderInfo b
on b.OraderNum in (a.orderList)
right join orderInfo b
on b.OraderNum in (a.orderList)