sql server 2012 - How to pivot data -


i use pivot function in following query display dateadded, accountname, campaign, campaigngroup on left side , summation of values across top summed across top

 select convert(varchar(10) , ct.dtadded , 120)dateadded  , upper(szaccountname)dealer  , upper(c.szcampaign)campaign  , upper(cg.szcampaigngroup)campaigngroup  , case    when d.dialid not null        1        else 0    end namesreceived  , attempts callattempts  , case    when callflag = 1 , attempts < c.nmaxattempts , d.agentid != -1        1        else 0    end eligibleremaining  , case    when szfaxtype '%appointment%'        1        else 0    end apptfaxes  , case    when szfaxtype '%hot%'        1        else 0    end hotfaxes  , case    when szfaxtype '%service opportunity%'        1        else 0    end serviceopfaxes  , case    when szfaxtype '%basic%'        1        else 0    end basicfaxes  , case    when szq25 in('now' , '30 days' , '90 days')        1        else 0    end inthemarket  , case    when crc in(                select szcrc collate sql_latin1_general_cp1_ci_as                  dbcallcenter..tblcalldispositionmap                  bsurveyrecord = 1)        1        else 0    end completedsurveys  , case    when crc in(                select szcrc collate sql_latin1_general_cp1_ci_as                  dbcallcenter..tblcalldispositionmap                  bbadrecord = 1)        1        else 0    end badrecords  , case    when crc in(                select szcrc collate sql_latin1_general_cp1_ci_as                  dbcallcenter..tblcalldispositionmap                  bcontactrecord = 1)        1        else 0    end contacts  , case    when crc in(                select szcrc collate sql_latin1_general_cp1_ci_as                  dbcallcenter..tblcalldispositionmap                  bpitchrecord = 1)        1        else 0    end pitches  , case    when crc in(                select szcrc collate sql_latin1_general_cp1_ci_as                  dbcallcenter..tblcalldispositionmap                  bdncrecord = 1)        1        else 0    end dncrecords 

from ... where...


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -