Insert data in ssrs table in the query

天涯浪子 提交于 2019-12-12 03:21:49

问题


I would like to insert some data in the ssrs table. I would like to show it like this here:

How can I add these data in my query in SSRS. I have no possibility to change something in the database.

       | 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%

The Problem is: Last week on wednesday the database did not recorded the data from Group A and Group B. And I have no possibility to correct/add the missing data in the database. And thats why I would like to add these missed data in my query and show it in the report.

My query:

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

When I realized that the data was not recorded I did written down the data on paper.


回答1:


To add manual data to your posted query, you can use UNION ALL and VALUES like so:

First make sure you get your 'additional data' correct on its own. Try this example:

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);

I am making many assumptions here as you have not provided enough info in your question.

Anyway if that is correct, then you simply attach it to your original data with 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);


来源:https://stackoverflow.com/questions/38630652/insert-data-in-ssrs-table-in-the-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!