合并为一个:select
aa.*,bb.*
from
(select
a.so,c.cartoonid
from
dbo.Nike_factory a
join
Nike_factory_line b on b.facid=a.id and b.container=@container_number and b.tag='P'
join
Nike_factory_cartoon c on b.id=c.lineid )aa
full join
(select carton_id,shipping_order
from Tbl_BENIKE2_STUFFING
where container_number=@container_number and status= 'P ')bb on aa.cartoonid=bb.carton_id
where
nullif(aa.cartoonid,bb.carton_id) is not null
aa.*,bb.*
from
(select
a.so,c.cartoonid
from
dbo.Nike_factory a
join
Nike_factory_line b on b.facid=a.id and b.container=@container_number and b.tag='P'
join
Nike_factory_cartoon c on b.id=c.lineid )aa
full join
(select carton_id,shipping_order
from Tbl_BENIKE2_STUFFING
where container_number=@container_number and status= 'P ')bb on aa.cartoonid=bb.carton_id
where
nullif(aa.cartoonid,bb.carton_id) is not null
我的a和b表数据没有哪个数据大于哪个。
可能有a表比b表多,或者b比a多。
我发现full join没有完全能把结果全部找出来。当然我是做的windows服务程序。
我系统需要统计这些不正常数据所占比例。
我把上面结果读到内存再做处理。
因为我们系统禁止使用proc
我需要把配对和不配对的打印出来。所以到这些已经够了。
自然使用proc效率也会提升不少。