sql - Display Months in Column Chart That have no Data -
i have ssrs column chart 2 category groups x-axis sort data based on year first, followed date. additionally have parameter on chart in end user can pick month in wish see data, , chart displays data relevant month.. trying have chart display columns months, if there no information available month (ideally, month display 0 there no data), opposed months have data based on filter. query have in dataset:
select count(c.statecodename) codename, c.statecodename, datename(mm, c.expireson) month, datename(yyyy, c.expireson) year, datepart(yyyy, c.expireson) yearnum, datepart(m, c.expireson) monthnum table1 c (c.expireson not null) , (datename(mm, c.modifiedon) in (@reportparameter1)) group datename(mm, c.expireson), datename(yyyy, c.expireson), datepart(yyyy, c.expireson), datepart(m, c.expireson), c.statecodename union select count(d.statecodename) codename, d.statecodename collate database_default, datename(mm, d.expireson) month, datename(yyyy, d.expireson) year, datepart(yyyy, d.expireson) yearnum, datepart(m, d.expireson) monthnum table2 d (d.expireson not null) , (datename(mm, d.modifiedon) in (@reportparameter1)) group datename(mm, d.expireson), datename(yyyy, d.expireson), datepart(yyyy, d.expireson), datepart(m, d.expireson), d.statecodename order yearnum, monthnum
is there way in can assign null values rest of months display such in column chart? far have tried create dataset retrieved months, , used lookup expression month parameter, did not anything. have tried check in clause datename(mm, c.expireson) null did not work. offer me approach how accomplish this? in advance!
create temporary or variable table year , month this:
select year , month table left join query you've listed above on year , month.
declare @date datetime declare @forecast table ([yy] int, [mm] varchar(15)) set @date = getdate() while (select datediff(m,@date,getdate())) > -12 begin insert @forecast (yy, mm) values (datepart(year,@date),datename(month,@date)) set @date = dateadd(m,-1,@date) if (select datediff(m,@date,getdate())) > 23 break else continue end select f.yy, f.mm, a.codename, a.statecodename @forecast f left outer join ( select count(c.statecodename) codename, c.statecodename, datename(mm, c.expireson) month, datename(yyyy, c.expireson) year table1 c (c.expireson not null) , (datename(mm, c.modifiedon) in (@reportparameter1)) group datename(mm, c.expireson), datename(yyyy, c.expireson), c.statecodename union select count(d.statecodename) codename, d.statecodename collate database_default, datename(mm, d.expireson) [month], datename(yyyy, d.expireson) [year] table2 d (d.expireson not null) , (datename(mm, d.modifiedon) in (@reportparameter1)) group datename(mm, d.expireson), datename(yyyy, d.expireson), d.statecodename ) on f.yy = a.[year] , f.mm = a.[month]
Comments
Post a Comment