日期:2014-05-17  浏览次数:20579 次

查询语句反应慢的问题
以下这段代码是查询最近五个月有交易的和新建两个月之类的供应商,但是查询速度很慢需要30s左右,请问各位大虾有没有什么好的建议???
CompanyCode in之前和之后的语句分开查询速度都很快!!
SELECT  distinct CompanyCode AS Code, '' AS Parent, CompanyName AS NAME, CompanyName AS Description, 0 AS Layer  
FROM eCompany  
WHERE (1 = 1)  AND (DeleteMark = '') and CompanyCode in(select distinct parent 
from (SELECT VendorCode AS Code, CompanyCode AS Parent, VendorCode AS NAME,  '客户编码:' + VendorCode + '
类别:' + (CASE BCFlag WHEN 'A' THEN N'国内区外' WHEN 'T' THEN N'区内' ELSE N'其他' END)  + 'Incoterm:' + Incoterm + '
PaymentTerm:' + PaymentTerm + N' 组织机构代码:' + OrganizationCode AS Description, 1 AS Layer  
FROM eVendor  except
SELECT VendorCode AS Code, CompanyCode AS Parent, VendorCode AS NAME,  '客户编码:' + VendorCode + '
类别:' + (CASE BCFlag WHEN 'A' THEN N'国内区外' WHEN 'T' THEN N'区内' ELSE N'其他' END)  + 'Incoterm:' + Incoterm + '
PaymentTerm:' + PaymentTerm + N' 组织机构代码:' + OrganizationCode AS Description, 1 AS Layer  
FROM eVendor  
WHERE (ISNULL(CompanyCode, '') <> '')  AND (DeleteMark = '') and vendorcode not in 
(SELECT distinct vendorcode FROM eOneDayHead WHERE (DATEDIFF(dd, UpdateTime, GETDATE()) < 150) 
union
select distinct vendorcode from tqsmcpackinghead  where (datediff(dd,createdate,getdate())<150)
    union  select distinct  vendorcode from evendor where datediff(dd,updatetime,getdate())<60)) as D)
查询速度

------解决方案--------------------

SELECT  DISTINCT
        CompanyCode AS Code ,