reporting services - Calendar returning duplicate lines per employee -
i have created simple table in ssrs has employees down left hand side , each column number 1 - 31. when employee books holiday puts x in dates on holiday using if function if day between date , date column.
this works fine when there more 1 holiday booked in month employee have duplicate lines rather going along same line in table. when adding in group function shows first holiday booked in month. possible show lines in one?
here's sql:
select * ,firstname + ' ' + lastname 'full' ,datediff(d, holidaystart, holidayend) 'days' ,day(dateadd(s, - 1, dateadd(mm, datediff(m, 0, holidaystart) + 1, 0))) lastday dbo.holdates month(holidaystart) = param1 , holyear = '8' , holidaystat = 'approved' , location = isnull(param2, location) , (holyear = @param3 - 2005) or month(holidayend) = param1 , (holyear = param3 - 2005) , holidaystat = 'approved' , location = isnull(param2, location) order (firstname + ' ' + lastname)
this gets easier if generate range of dates want report cte, , join actual holiday dates. cte this:
declare @fromdate date = '20130701', @todate date = '20130801'; dates ( select @fromdate "date" union select dateadd(dd, 1, "date") dates dateadd(dd, 1, "date") <= @todate ) -- continued below...
then select data against cte such:
select dates."date" ,case when h.holidaystart not null 'x' else null end hasholiday ,firstname + ' ' + lastname "full" ,datediff(d, holidaystart, holidayend) "days" dates left join @holdates h on dates."date" between h.holidaystart , h.holidayend month(holidaystart) = param1 , h.holyear = '8' , h.holidaystat = 'approved' , h.location = isnull(param2, location) order (firstname + ' ' + lastname)
this give result set along these lines:
date hasholiday full --------------- ----------- --------- 2013-07-01 null null 2013-07-02 null null 2013-07-03 null null 2013-07-04 null null 2013-07-05 x john 2013-07-05 x mark 2013-07-06 x john 2013-07-06 x mark 2013-07-07 x john etc.
now in ssrs, need add matrix you:
- group rows day of month
- group columns based on month (if needed) , on person
- use
hasholiday
value in cells
in case, above dataset more convenient basis creating calendar-like reports.