- 打卡等级:无名新人
- 打卡总天数:3
- 打卡月天数:1
- 打卡总奖励:5
- 最近打卡:2024-11-01 16:19:28
|
发表于 2018-12-21 09:09:49
|
显示全部楼层
insert into tempdb..[TempSTAccount_UFIDA_WIN_1N6U1O0IBO9_1_Temp1] SELECT cWhCode, Rdrecords.cInvCode,(CASE WHEN cFree1=N''THEN NULL ELSE cFree1 END) AS cFree1 ,(CASE WHEN cFree2=N''THEN NULL ELSE cFree2 END) AS cFree2 , (CASE WHEN cFree3=N''THEN NULL ELSE
cFree3 END) AS cFree3 ,(CASE WHEN cFree4=N''THEN NULL ELSE cFree4 END) AS cFree4 , (CASE WHEN cFree5=N''THEN NULL ELSE cFree5 END) AS cFree5 ,(CASE WHEN cFree6=N''THEN NULL ELSE cFree6 END) AS cFree6 , (CASE WHEN cFree7=N''THEN NULL ELSE cFree7 END) AS cFree7
,(CASE WHEN cFree8=N''THEN NULL ELSE cFree8 END) AS cFree8 , (CASE WHEN cFree9=N''THEN NULL ELSE cFree9 END) AS cFree9 ,(CASE WHEN cFree10=N''THEN NULL ELSE cFree10 END) AS cFree10 , (CASE WHEN cBatch=N''THEN NULL ELSE cBatch END) AS cBatch, (case when
Inventory.cSRPolicy ='LP' and Inventory.bspecialorder = 1 and isnull(blpusefree,0)=0 then ISNULL(iSoType,0) else 0 end) AS iSoType, (case when Inventory.cSRPolicy ='LP' and Inventory.bspecialorder = 1 and isnull(blpusefree,0)=0 then ISNULL(iSoDID,'') else '' end) as iSoDID,isnull(Rdrecords.cvmivencode,'') as cvmivencode, Sum(CASE WHEN bRdFlag=1 THEN isnull(iQuantity,0) ELSE isnull(-iQuantity,0) END) AS iAccountQuantity, Sum(CASE WHEN bRdFlag=1 THEN isnull(iNum,0) ELSE isnull(-iNum,0) END) AS iAccountNum FROM rdrecord34 RdRecord INNER JOIN rdrecords34 RdRecords ON RdRecord.ID = RdRecords.ID INNER JOIN Inventory On Rdrecords.cInvcode=Inventory.cInvCode WHERE (1=1) And Coalesce(Inventory.dEDate,'9999-01-01') > '2015-01-21' And Rdrecord.cWhcode=N'04' And Rdrecords.cInvCode IN( select cinvcode from tempdb..TempUFIDA_WIN_1N6U1O0IBO9_1 ) And (( bISSTQC=1 and Isnull(cHandler,N'')<>N'') OR ((Rdrecord.cVouChType=N'08' and bIaFirst<>1 and bISSTQC<>1) and Isnull(cHandler,N'')<>N'') OR
((Rdrecord.cVouChType=N'09' and bIaFirst<>1 and Isnull(Rdrecord.cHandler,N'')<>N'') ) OR ((Rdrecord.cVouChType=N'01' and isnull(bIaFirst,0)<>1 and isnull(bPuFirst,0)<>1 and isnull(bOMFirst,0)<>1 and isnull(bISSTQC,0)<>1 ) and Isnull(Rdrecord.cHandler,N'')<>N'' and Rdrecord.dDate >='2014-12-01') OR ((Rdrecord.cVouChType=N'32' and isnull(bIaFirst,0)<>1 and isnull(bPuFirst,0)<>1 and isnull(bOMFirst,0)<>1 and isnull(bISSTQC,0)<>1 ) and Isnull(Rdrecord.cHandler,N'')<>N'' and Rdrecord.dDate >='2014-12-01') OR ((Rdrecord.cVouChType=N'10' and isnull(bIaFirst,0)<>1 and isnull(bPuFirst,0)<>1 and isnull(bOMFirst,0)<>1 and isnull(bISSTQC,0)<>1 ) and Isnull(Rdrecord.cHandler,N'')<>N'') OR ((Rdrecord.cVouChType=N'11' and isnull(bIaFirst,0)<>1 and isnull(bPuFirst,0)<>1 and isnull(bOMFirst,0)<>1 and isnull(bISSTQC,0)<>1 ) and Rdrecord.cBusType<>N'假退料' and Isnull(Rdrecord.cHandler,'')<>'')) And ((Rdrecord.dDate < '2014-12-01' And IsNull(Rdrecord.bIsSTQc,0) = 1)
Or (Rdrecord.dDate >= '2014-12-01'
And IsNull(Rdrecord.bPUFirst,0) = 0
And IsNull(Rdrecord.bIAFirst,0) = 0
And IsNull(Rdrecord.bOMFirst,0) = 0
And (not (Rdrecord.cBusType = N'假退料'and Rdrecord.cVouchType = 11))
)
) And (case when isnull(rdrecord.cvouchtype,'') ='08' or isnull(rdrecord.cvouchtype,'') ='09' then rdrecord.dveridate when isnull(rdrecord.cvouchtype,'') ='01' then rdrecord.dveridate when isnull(rdrecord.cvouchtype,'') ='32' then rdrecord.dveridate when isnull(rdrecord.cvouchtype,'') ='10' then rdrecord.dveridate when isnull(rdrecord.cvouchtype,'') ='11' then rdrecord.dveridate else case when rdrecord.dveridate >=N'2015-01-01' then '2015-01-01' else rdrecord.ddate end end ) <='2015-01-21' and (case when isnull(rdrecord.cvouchtype,'') ='08' or isnull(rdrecord.cvouchtype,'') ='09' then rdrecord.dveridate when isnull(rdrecord.cvouchtype,'') ='01' then rdrecord.dveridate when isnull(rdrecord.cvouchtype,'') ='32' then rdrecord.dveridate when isnull(rdrecord.cvouchtype,'') ='10' then rdrecord.dveridate when isnull(rdrecord.cvouchtype,'') ='11' then rdrecord.dveridate else case when rdrecord.dveridate >=N'2015-01-01' then '2015-01-01' else rdrecord.ddate end end ) >='2015-01-01' Group By cWhCode, Rdrecords.cInvCode,(CASE WHEN cFree1=N''THEN NULL ELSE cFree1 END) ,(CASE WHEN cFree2=N''THEN NULL ELSE cFree2 END) , (CASE WHEN cFree3=N''THEN NULL ELSE cFree3 END) ,(CASE WHEN cFree4=N''THEN NULL ELSE cFree4 END) , (CASE WHEN cFree5=N''THEN NULL ELSE cFree5 END) ,(CASE WHEN cFree6=N''THEN NULL ELSE cFree6 END) , (CASE WHEN cFree7=N''THEN NULL ELSE cFree7 END) ,(CASE WHEN cFree8=N''THEN NULL ELSE cFree8 END) , (CASE WHEN cFree9=N''THEN NULL ELSE cFree9 END) ,(CASE WHEN cFree10=N''THEN NULL ELSE cFree10 END) , (CASE WHEN cBatch=N''THEN NULL ELSE cBatch END) , ISNULL(Rdrecords.cvmivencode,'') , (case when Inventory.cSRPolicy ='LP' and Inventory.bspecialorder = 1 and isnull(blpusefree,0)=0 then ISNULL(iSoType,0) else 0 end) , (case when Inventory.cSRPolicy ='LP' and Inventory.bspecialorder = 1 and isnull(blpusefree,0)=0 then ISNULL(iSoDID,'') else '' end) |
|