日期:2014-05-18  浏览次数:20516 次

请各位高手帮忙给优化一下这个代码`(C,D,E,F,G表中数据量很大)
select  
A.伝票NO,
CONVERT(VARCHAR(100),getdate(),111)   AS   納品日,
5   as   店CD,
A.部門CD,
B.行NO,
convert(varchar(100),A.発注日,111)   AS   発注日,
A.納品予定日   as   納品予定日,  
2   AS   伝票種別,
B.JAN,
C.ProdName   AS   商品名,
C.SubName   AS   規格,  
D.name   AS   店名,  
A.ベンダーCD,  
E.[name]   AS     ベンダー名,  
F.bandingunits   AS   入数,  
B.発注数,  
B.納品数   AS   納品予定数,  
B.発注数   AS   出庫数,  
(0-B.発注数)   AS   納品数,  
NULL   AS   軽量区分,  
round(B.原単価,4)   as   原単価,  
B.売単価,  
B.原価金額,  
B.売価金額,  
A.原価合計,  
A.売価合計,
CONVERT(   VARCHAR(100),A.入力日,111)   AS   入力日,  
0   AS   検品ステータス,
1   as   検品担当者CD,
'ytjty '   as   検検品担当者名,    
getdate()   AS   登録日時,  
A.更新日時,    
A.システム区分    
FROM    
YNTDEV244.[TrialPo].dbo.T_D振替伝票   A  
INNER   JOIN  
YNTDEV244.[TrialPo].dbo.T_D振替明細   B  
ON    
A.伝票NO=B.伝票NO  
AND  
A.店CD=B.店CD  
AND    
A.納品日=B.納品日  
AND    
A.ベンダーCD=B.ベンダーCD    


LEFT   JOIN  

YNTDEV244.[TrialPo].dbo.products   C  
on
B.JAN=C.prodcode    
LEFT   JOIN    
YNTDEV244.[TrialPo].dbo.branches   D  
ON    
A.店CD=D.branchcode    
LEFT   JOIN    
YNTDEV244.[TrialPo].dbo.suppliers   E    
ON  
CONVERT(VARCHAR(12),A.ベンダーCD   )=   E.supplier  
LEFT   JOIN    
YNTDEV244.[TrialPo].dbo.productcodes   G  
ON    
C.prodint   =   G.prodint  
LEFT   JOIN    
(select   distinct   bandingunits,varint   from     YNTDEV244.[TrialPo].dbo.PRSourcePrefs   )   F    
ON  
G.varint   =   F.varint  
WHERE    
A.部門CD   IN   (SELECT   level2   FROM   YNTDEV244.TrialPo.dbo.structlevels   WHERE   level1=22)  
AND    
A.伝票NO   NOT   IN  
(SELECT   伝票NO   FROM   FreshInformation_127_0_0_1   WHERE   伝票NO=A.伝票NO     AND   店CD=A.店CD   AND   部門CD=A.部門CD   AND   行NO=B.行NO)  
AND  
A.店CD=5  
AND   A.納品予定日   between   '2006/04/13 '   and   '2007/07/13 '  
AND   A.検品区分=0    
AND   A.伝票区分=30  


------解决方案--------------------
用分块查找实施,建立临时表,把数据量大的表分开处理