"select temp1.*,isnull(temp3.PartCode,temp2.partCode) partCode,case WHEN ISNULL(TEMP2.InvbillNum,'')<>'' THEN isnull(temp2.Qty,0) ELSE 0 END invQty from (\n"+
"case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([200],0)=0 then ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)\n"+
"case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([800],0)=0 then ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)\n"+
"case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([200],0)-ISNULL([800],0)>0 then ISNULL([100],0)\n"+
"ElSE 0 END SE_SA_DIFF_QTY,\n"+
"case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([200],0)-ISNULL([800],0)=ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0) then \n"+