sql - exclude some data from a table SSRS -
i want exclude weekend , holiday table:
for example in picture exclude date 19.01. , 10.01 table or should show 0 in 10.01.2016.
this code:
select * ( select intervaldate datum, tsystem.name name, sum(case when name = 'maschine 1' units else 0 end) maschine1, sum(case when name = 'maschine 2' units else 0 end) maschine2, sum(case when name = 'maschine 3' units else 0 end) maschine3, count inner join tsystem on count.systemid = tsystem.id intervaldate between @startdatetime , @enddatetime , tsystem.name in ('m101','m102','m103','m104','m105','m107','m109','m110', 'm111', 'm113', 'm114', 'm115') group intervaldate, tsystem.name ) s
i think best approach create table in database , store weekend , holidays dates use table filter query.
something this:
select * ( select intervaldate datum, tsystem.name name, sum(case when name = 'maschine 1' units else 0 end) maschine1, sum(case when name = 'maschine 2' units else 0 end) maschine2, sum(case when name = 'maschine 3' units else 0 end) maschine3, count inner join tsystem on count.systemid = tsystem.id intervaldate between @startdatetime , @enddatetime , intervaldate not in (select weekendorholidaydate myweekendandholidaytable) , tsystem.name in ('m101','m102','m103','m104','m105','m107','m109','m110', 'm111', 'm113', 'm114', 'm115') group intervaldate, tsystem.name ) s
the below query exclude weekdays only. there no way produce holidays sql if want exclude holidays have store somewhere in database.
select * ( select intervaldate datum, tsystem.name name, sum(case when name = 'maschine 1' units else 0 end) maschine1, sum(case when name = 'maschine 2' units else 0 end) maschine2, sum(case when name = 'maschine 3' units else 0 end) maschine3, count inner join tsystem on count.systemid = tsystem.id intervaldate between @startdatetime , @enddatetime , ((datepart(dw, intervaldate) + @@datefirst) % 7) not in (0, 1) , tsystem.name in ('m101','m102','m103','m104','m105','m107','m109','m110', 'm111', 'm113', 'm114', 'm115') group intervaldate, tsystem.name ) s
let me know if helps you.
Comments
Post a Comment