Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have table
Dummy with following fields
SQL
Day int 
Name varchar(50)
Amount int

here Name Takes only A or B
i want result like this

Day  A     B
1   100   50
2    35    26

i want some of amount For A and B for each Day. User Can have any no of records for one day

Any help is appreciated
Posted
Updated 25-Jan-12 3:02am
v2

SQL
select  sum(A+B) as OneDay from Days
Group by Day
 
Share this answer
 
Here is the solution :
SQL
select * from (select [DAY],name, amount  from Dummy) upt 
pivot
(
sum(amount)
for name in ([A], [B])
) as p


PIVOT documentation :
http://msdn.microsoft.com/en-us/library/ms177410.aspx[^]

Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900