首页 > 解决方案 > SQL 查询优化和 SSRS 报告性能

问题描述

下面的代码来自 SSRS 报告,该报告需要很长时间才能执行。它从包含数百万条记录的存档表中检索数据。代码不是我写的,所以不太了解。有没有办法优化以下代码?这是从活动监视器检查时导致问题的代码的一部分。在数据库中创建索引也需要很长时间。有没有更好的方法?

Insert into #MandrillResponses 
select EmailResultID, eventtype,
    case when IsNull(count(*),0) > 0 then 1 else 0 end 
from #EmailsSent s
join TDN_MandrillResponse r on (s.UniqueID = r.EmailResultID) where eventtype not in ('open','click','Deferral')
group by EmailResultID, eventtype
insert into #MandrillResponses  
select EmailResultID, eventtype, max(count)    
from #EmailsSent s
    join TDN_MandrillResponse r on (s.UniqueID = r.EmailResultID) where eventtype in ('open','click','Deferral')
    group by EmailResultID, eventtype
UNION
select EmailResultID, eventtype, max(count)  
from #EmailsSent s
    join archive_TDN_MandrillResponse r on (s.UniqueID = r.EmailResultID) where eventtype in ('open','click','Deferral')
group by EmailResultID, eventtype;

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

标签: sqlsql-serverreporting-services

解决方案


推荐阅读