我希望在图片中显示两个时段的Microsoft SQL Reportbuilder 3.0 2012中的报告。我做了一个查询,向我展示了红色时期,但我似乎无法在一个报告中将黑色时段与红色时段相结合。它们需要彼此相邻的两个不同的列。 本报告的目的是从开始到今天显示某个项目的所有预订,并特别针对特定月份查看它们。 甚至有办法做到这一点还是不可能?
答案 0 :(得分:1)
以为我会分享答案。这是我用来解决问题的代码。
SELECT
tblReg.PurchaseOrderId,
tblReg.Reference AS PO,
SUM(HoursBefore) AS HoursBefore,
SUM(HoursBefore)/8 AS DaysBefore,
SUM(HoursBetween) AS HoursBetween,
SUM(HoursBetween)/8 AS DaysBetween,
SUM(HoursAfter) AS HoursAfter,
SUM(HoursAfter)/8 AS DaysAfter,
MIN(BudgetDays) AS BudgetDays
FROM
(
SELECT
po.PurchaseOrderId,
po.Reference,
BudgetDays,
CASE
WHEN reg.RegistrationDate < @StartDate THEN DurationHours
ELSE 0
END AS HoursBefore,
CASE
WHEN reg.RegistrationDate >= @StartDate AND reg.RegistrationDate <= @EndDate THEN DurationHours
ELSE 0
END AS HoursBetween,
CASE
WHEN reg.RegistrationDate > @EndDate THEN DurationHours
ELSE 0
END AS HoursAfter
FROM Registration reg
INNER JOIN PurchaseOrder po ON reg.PurchaseOrderId = po.PurchaseOrderId
WHERE po.statuscid = 1 AND reg.IsBillable = 1 AND SetNonBillable = 0 --AND reg.RegistrationDate >= @StartDate AND reg.RegistrationDate <= @EndDate
)tblReg
GROUP BY tblReg.PurchaseOrderId, tblReg.Reference
ORDER BY tblReg.Reference;