我想从我的桌子中排除周末和假期:
例如在这张图片中我想排除日期19.01。和我的表中的10.01或它应该在10.01.2016中只显示0。
这是我的代码:
SELECT *
FROM (
Select intervaldate as Datum, tsystem.Name as Name,
SUM(case when Name = 'Maschine 1' then Units else 0 end) as Maschine1,
Sum(case when Name = 'Maschine 2' then Units else 0 end) as Maschine2,
Sum(case when Name = 'Maschine 3' then Units else 0 end) as Maschine3,
from Count inner join tsystem ON Count.systemid = tsystem.id
where IntervalDate BETWEEN @StartDateTime AND @EndDateTime
and tsystem.Name in ('M101','M102','M103','M104','M105','M107','M109','M110', 'M111', 'M113', 'M114', 'M115')
group by intervaldate, tsystem.Name
) as s
答案 0 :(得分:0)
为了排除周末......你可以使用日期功能和IIF条件。如果周数为7或1,则在报告中排除...您可以通过右键单击报告属性并选择过滤器来执行此操作。
答案 1 :(得分:0)
我认为最好的方法是在数据库中创建一个表并存储所有周末和假日日期,然后使用该表过滤您的查询。
这样的事情:
SELECT *
FROM (
Select intervaldate as Datum, tsystem.Name as Name,
SUM(case when Name = 'Maschine 1' then Units else 0 end) as Maschine1,
Sum(case when Name = 'Maschine 2' then Units else 0 end) as Maschine2,
Sum(case when Name = 'Maschine 3' then Units else 0 end) as Maschine3,
from Count inner join tsystem ON Count.systemid = tsystem.id
where IntervalDate BETWEEN @StartDateTime AND @EndDateTime
and IntervalDate NOT IN (select WeekendOrHolidayDate from MyWeekendAndHolidayTable)
and tsystem.Name in ('M101','M102','M103','M104','M105','M107','M109','M110', 'M111', 'M113', 'M114', 'M115')
group by intervaldate, tsystem.Name
) as s
以下查询仅排除工作日。如果你想要排除假期,你必须将它存储在数据库的某个地方,就无法从SQL中产生假期。
SELECT *
FROM (
Select intervaldate as Datum, tsystem.Name as Name,
SUM(case when Name = 'Maschine 1' then Units else 0 end) as Maschine1,
Sum(case when Name = 'Maschine 2' then Units else 0 end) as Maschine2,
Sum(case when Name = 'Maschine 3' then Units else 0 end) as Maschine3,
from Count inner join tsystem ON Count.systemid = tsystem.id
where IntervalDate BETWEEN @StartDateTime AND @EndDateTime
and ((DATEPART(dw, IntervalDate) + @@DATEFIRST) % 7) NOT IN (0, 1)
and tsystem.Name in ('M101','M102','M103','M104','M105','M107','M109','M110', 'M111', 'M113', 'M114', 'M115')
group by intervaldate, tsystem.Name
) as s
如果这有助于您,请告诉我。
答案 2 :(得分:0)
右键单击Tablix中的行组,然后选择“行可见性”。在“更改显示”选项中,选择“基于表达式显示或隐藏”。在表达式中,这应该有效:
=iif(CDate(Fields!Date.Value).DayOfWeek = DayOfWeek.Saturday, true, iif(CDate(Fields!Date.Value).DayOfWeek = DayOfWeek.Sunday, true, false))
如果有大量数据,出于性能原因,我建议在数据库端修剪这些行。