sql server - T sql group by only column -


i have below columns , column's data types

dailyworkinghours daily (money) case_completion_hour casecomp (money) xdate month (datetime) 

i have below query

select  sum(cpw.dailyworkinghours) daily,  sum(ca.case_completion_hour) / 60 casecomp,  datename( month , dateadd( month , month(ca.xdate) , 0 ) - 1 ) month  reseller_user_profiles rup  join cases c on c.reseller_user_id=rup.reseller_user_id join case_action ca on ca.case_id=c.case_id join tblcaseprojectworkers cpw on c.reseller_user_id=cpw.reselleruserid  join tblcaseprojectsnew cpn on cpn.id=c.project_id  group  datename( month , dateadd( month , month(ca.xdate) , 0 ) - 1 )   order  datename( month , dateadd( month , month(ca.xdate) , 0 ) - 1 ) 

if run query returns data below

daily (column)  -  casecomp (column)  -  month (column)  1088,00           -  0,3333             -  february  544,00            -  0,3344             -  february  321,00            -  0,3377             -  february  150,00            -  0,3387             -  january  332,00            -  0,3330             -  january  658,00            -  4,3331             -  april 

question:

how can select query below result (i want display 12 months if month empty)

daily (column)  -  casecomp (column)  -  month (column)  150,00            -  0,3387             -  january  332,00            -  0,3330             -    1088,00           -  0,3333             -  february  544,00            -  0,3344             -    321,00            -  0,3377             -    null              -  null               -  march  658,00            -  4,3331             -  april  null              -  null               -  may  null              -  null               -  june  null              -  null               -  july  null              -  null               -  august  null              -  null               -  september  null              -  null               -  october  null              -  null               -  november  null              -  null               -  december 

month column grouping inside of month column in result query. change in query code according achieve this?

give try.

    create table #months (num int, name varchar(15))      insert #months select 1, 'january'     insert #months select 2, 'february'     insert #months select 3, 'march'     insert #months select 4, 'april'     insert #months select 5, 'may'     insert #months select 6, 'june'     insert #months select 7, 'july'     insert #months select 8, 'august'     insert #months select 9, 'september'     insert #months select 10, 'october'     insert #months select 11, 'november'     insert #months select 12, 'december'       select *              #months m         left join              (             select              sum(cpw.dailyworkinghours) daily,              sum(ca.case_completion_hour) / 60 casecomp,              datename( month , dateadd( month , month(ca.xdate) , 0 ) - 1 ) month              reseller_user_profiles rup              join cases c on c.reseller_user_id=rup.reseller_user_id             join case_action ca on ca.case_id=c.case_id             join tblcaseprojectworkers cpw on c.reseller_user_id=cpw.reselleruserid              join tblcaseprojectsnew cpn on cpn.id=c.project_id              group              datename( month , dateadd( month , month(ca.xdate) , 0 ) - 1 )                ) yours             on yours.month = m.name order m.num 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -