我想在ssrs表中插入一些数据。 我想在这里这样展示:
如何在SSRS中的查询中添加这些数据。我无法在数据库中更改某些内容。
| P1|P2 |P3 |P4 |P5 |P6 |P7 |P8
Group A|84%|87%|81%|81%|79%|96%|86%|88%
Group B|66%|22%|79%|64%|53%|94%|5% |23%
问题是: 上周三,数据库没有记录A组和B组的数据。我无法在数据库中更正/添加缺失的数据。这就是为什么我想在我的查询中添加这些错过的数据并在报告中显示它。
我的查询:
SELECT *
FROM (
Select
intervaldate as Datum
,tsystem.Name as Name
,team as group
,SUM(GoodUnits) As Goods
,SUM(TheoreticalUnits) As Units
from tCount inner join tsystem ON tCount.systemid = tsystem.id
where IntervalDate >= @StartDateTime AND IntervalDate <= @EndDateTime
group by intervaldate
) c
inner join
(
SELECT
sh.Date as Datum,
sc.Name as Name
FROM tHistory sh
INNER JOIN tSchedule sc ON (sc.ID = sh.ScheduleID)
WHERE Scheduled != 0
) p ON p.Name = c.Name
当我意识到数据未被记录时,我确实在纸上写下了数据。
答案 0 :(得分:0)
要向发布的查询添加手动数据,您可以使用UNION ALL
和VALUES
,如下所示:
首先确保您获得了额外的数据&#39;自己纠正。试试这个例子:
SELECT Datum,Name,[Group],Goods,Units
FROM (
VALUES
(CAST('2015-01-01' AS DATE),'AName','A',10.32,20.76),
(CAST('2015-01-01' AS DATE),'AName','B',12.72,16.15)
) AS ExtraData(Datum,Name,[Group],Goods,Units);
我在这里做了很多假设,因为你没有在你的问题中提供足够的信息。
无论如何,如果这是正确的,那么您只需使用UNION ALL
SELECT Datum,Name,[Group],Goods,Units
FROM (
Select
intervaldate as Datum
,tsystem.Name as Name
,team as [Group]
,SUM(GoodUnits) As Goods
,SUM(TheoreticalUnits) As Units
from tCount inner join tsystem ON tCount.systemid = tsystem.id
where IntervalDate >= @StartDateTime AND IntervalDate <= @EndDateTime
group by intervaldate
) c
inner join
(
SELECT
sh.Date as Datum,
sc.Name as Name
FROM tHistory sh
INNER JOIN tSchedule sc ON (sc.ID = sh.ScheduleID)
WHERE Scheduled != 0
) p ON p.Name = c.Name
/* Original query ends. Now add more data */
UNION ALL
SELECT Datum,Name,[Group],Goods,Units
FROM (
VALUES
(CAST('2015-01-01' AS DATE),'AName','A',10.32,20.76),
(CAST('2015-01-01' AS DATE),'AName','B',12.72,16.15)
) AS ExtraData(Datum,Name,[Group],Goods,Units);