"case when ISNULL(A.qty,0) >ISNULL(b.qty,0) then '发运比EDI多'\n"+
"case\n"+
"when ISNULL(A.qty,0) <ISNULL(b.qty,0) then '发运比EDI少'\n"+
"when ISNULL(A.qty,0) >ISNULL(b.qty,0) and ISNULL(b.qty,0)=0 then 'WMS有发货EDI无订单'\n"+
"END State\n"+
"when ISNULL(B.qty,0)=0 and ISNULL(A.qty,0)<0 then 'WMS有发货EDI无订单'\n"+
"from\n"+
"when ISNULL(A.qty,0) >ISNULL(b.qty,0) and ISNULL(b.qty,0)>0 then 'WMS有发货多余EDI订单'\n"+
"(select PN,LU,CustomerPartCodeNoSpace,sum(Qty) qty ,MAX(BillTime) BillTime from Set_BBAC_SE_DETAIL where BusinessType=1 and billtime>='2023-09-25 00:00:00' group by PN,CustomerPartCodeNoSpace,LU) a full join\n"+
"when ISNULL(A.qty,0) <ISNULL(b.qty,0) and ISNULL(a.qty,0)=0 then 'WMS漏发货EDI有订单'\n"+
"(select PN,LU,CustomerPartCodeNoSpace,sum(Qty) qty ,MAX(CreationTime) EDITime from Set_BBAC_SE_EDI group by PN,CustomerPartCodeNoSpace,LU) b on a.PN=b.PN and a.CustomerPartCodeNoSpace=b.CustomerPartCodeNoSpace\n"+
"END State\n"+
"WHERE isnull(A.qty,0)<>isnull(B.qty,0) ) temp order by EDITime,BillTime\n";
"from\n"+
"(select PN,LU,CustomerPartCodeNoSpace,sum(Qty) qty ,MAX(BillTime) BillTime from Set_BBAC_SE_DETAIL where BusinessType=1 and billtime>='2023-09-25 00:00:00' group by PN,CustomerPartCodeNoSpace,LU) a full join\n"+
"(select PN,LU,CustomerPartCodeNoSpace,sum(Qty) qty ,MAX(CreationTime) EDITime from Set_BBAC_SE_EDI group by PN,CustomerPartCodeNoSpace,LU) b on a.PN=b.PN and a.CustomerPartCodeNoSpace=b.CustomerPartCodeNoSpace\n"+
"WHERE isnull(A.qty,0)<>isnull(B.qty,0)) temp WHERE STATE!='WMS有发货多余EDI订单' order by EDITime,BillTime\n";
"case when ISNULL(A.qty,0) >ISNULL(b.qty,0) then '发运比EDI多'\n"+
"case\n"+
"when ISNULL(A.qty,0) <ISNULL(b.qty,0) then '发运比EDI少'\n"+
"when ISNULL(A.qty,0) >ISNULL(b.qty,0) and ISNULL(b.qty,0)=0 then 'WMS有发货EDI无订单'\n"+
"END State\n"+
"when ISNULL(B.qty,0)=0 and ISNULL(A.qty,0)<0 then 'WMS有发货EDI无订单'\n"+
"from\n"+
"when ISNULL(A.qty,0) >ISNULL(b.qty,0) and ISNULL(b.qty,0)>0 then 'WMS有发货多余EDI订单'\n"+
"(select PN,LU,CustomerPartCodeNoSpace,sum(Qty) qty ,MAX(BillTime) BillTime from Set_HBPO_SE_DETAIL where BusinessType=2 and billtime>='2023-09-25 00:00:00' group by PN,CustomerPartCodeNoSpace,LU) a full join\n"+
"when ISNULL(A.qty,0) <ISNULL(b.qty,0) and ISNULL(a.qty,0)=0 then 'WMS漏发货EDI有订单'\n"+
"(select PN,LU,CustomerPartCodeNoSpace,sum(Qty) qty ,MAX(CreationTime) EDITime from Set_HBPO_SE_EDI group by PN,CustomerPartCodeNoSpace,LU) b on a.PN=b.PN and a.CustomerPartCodeNoSpace=b.CustomerPartCodeNoSpace\n"+
"END State\n"+
"WHERE isnull(A.qty,0)<>isnull(B.qty,0) ) temp order by EDITime,BillTime\n";
"from\n"+
"(select PN,LU,CustomerPartCodeNoSpace,sum(Qty) qty ,MAX(BillTime) BillTime from Set_HBPO_SE_DETAIL where BusinessType=2 and billtime>='2023-09-25 00:00:00' group by PN,CustomerPartCodeNoSpace,LU) a full join\n"+
"(select PN,LU,CustomerPartCodeNoSpace,sum(Qty) qty ,MAX(CreationTime) EDITime from Set_HBPO_SE_EDI group by PN,CustomerPartCodeNoSpace,LU) b on a.PN=b.PN and a.CustomerPartCodeNoSpace=b.CustomerPartCodeNoSpace\n"+
"WHERE isnull(A.qty,0)<>isnull(B.qty,0)) temp WHERE STATE!='WMS有发货多余EDI订单' order by EDITime,BillTime\n";