sql server - Query to make rows into column values without using PIVOT -


i have following query , gives result shown below.

  select             sum(atm) atm,sum(cc) cc,sum(csh) csh ,sum(chk) chk      sales                      repid= 9000           , dateadd(dd,0,datediff(dd,0,idate)) ='2013-08-25 00:00:00' 

query result

how modify query without using pivot rerun result shown below. query result

this should work

select  'atm' type, sum(atm) amount   sales                    repid= 9000 , dateadd(dd,0,datediff(dd,0,idate)) ='2013-08-25 00:00:00' union select  'cc' type, sum(cc) amount   sales                    repid= 9000 , dateadd(dd,0,datediff(dd,0,idate)) ='2013-08-25 00:00:00' union select  'csh' type, sum(csh) amount   sales                    repid= 9000 , dateadd(dd,0,datediff(dd,0,idate)) ='2013-08-25 00:00:00' union select  'chk' type, sum(chk) amount   sales                    repid= 9000 , dateadd(dd,0,datediff(dd,0,idate)) ='2013-08-25 00:00:00' 

or, using cte:

;with cte(atm,cc,csh,chk)    (select  sum(atm),sum(cc),sum(csh),sum(chk) sales                      repid= 9000 , dateadd(dd,0,datediff(dd,0,idate)) ='2013-08-25 00:00:00' ) select  'atm' type,atm amount cte union select 'cc' ,cc  cte union select 'csh',csh cte union select 'chk',chk cte 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -