简体   繁体   中英

Insert data in ssrs table in the query

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.

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM