Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rohan_iiitc
Starting Member
11 Posts |
Posted - 2010-05-05 : 08:13:28
|
| Dear FriendsI would like to know how to get the below output.Table Structure is of TBL_BRANCH :Branch, BranchName, TYPE, SALE_QTYDesired Output-------------------------------------------| BRANCH | TYPE1 | TYPE2 | TYPE3 | TOTAL |-------------------------------------------| BRANCH1 | 05 | 12 | 09 | 26 | -------------------------------------------| BRANCH2 | 01 | 04 | 19 | 24 | -------------------------------------------| BRANCH3 | 15 | 22 | 01 | 38 | -------------------------------------------RegardsRohan |
|
|
apodemus
Starting Member
30 Posts |
Posted - 2010-05-05 : 08:46:37
|
| IF list of Type's is constant and known, you can use PIVOT :select BranchName Branch,[TYPE1], [TYPE2], [TYPE3], [TOTAL]from (select BranchName, type, sale_qtyfrom TBL_BRANCH union allselect BranchName, 'TOTAL' type, sale_qtyfrom TBL_BRANCH ) pppivot (SUM(sale_qty)FOR type IN ([TYPE1], [TYPE2], [TYPE3], [TOTAL])) as pti don't have you table, sorry for sythax's if will be somone :)apodemus |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-05 : 14:57:48
|
| you can just add up individual ones to get total no need of union all query------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|