First I used a query without the second select statement, the positive was that the report was really fast if I choose a long time period, but it displayed me every weekends and holidays. That was not a big issue, then I excluded every free days with the filter option in SSRS, after this the report showed me only the workdays, but the problem was, there were additional rows with a 0 and this affected the calculations.
The only solution was to add a second select statement "Scheduled". After I added an inner join the report runs very slow. The second Select Statement is a schedule and it excludes all the weekends and holidays, and this does not display any extra row if I run it. But the big Problem is, that the report runs really slow. And If I choose over a period of six month it displays me a "Timeout Error".
The query:
SELECT c.date,
c.team,
c.NAME,
c.prod,
c.product
FROM (SELECT intervaldate AS Date,
tsystem.NAME AS NAME,
productname AS Product,
teamname AS Team,
Sum(CASE
WHEN countername = 'Prod' THEN displayunits
ELSE 0
END) AS Prod
FROM count
INNER JOIN tsystem
ON count.systemid = tsystem.id
WHERE intervaldate >= @StartDateTime
AND intervaldate <= @EndDateTime
AND tsystem.id IN (SELECT systemid
FROM viewsystem
WHERE viewid = 122)
GROUP BY intervaldate,
teamname,
tsystem.NAME,
productname) c
INNER JOIN (SELECT sh.scheduled AS Scheduled,
sc.NAME AS NAME
FROM history sh
INNER JOIN schedule sc
ON ( sc.id = sh.scheduleid )
WHERE scheduled != 0) p
ON p.NAME = c.NAME
Is there any possibility to make it faster?
You need to replace below part of query (sub query) with join
-> and tsystem.ID in (Select SystemID from ViewSystem where ViewID = 122)
-> Inner JOIN ViewSystem on tsystem.ID=ViewSystem.SystemID where ViewID=122
Joins are way more faster than sub queries.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.