This is my sample Table
**BranchId GroupCode Cash Credit**
1000 AA 10 8644
1000 AA 12 1244
1000 BB 20 7535
1000 CC 30 5633
1001 AA 50 5763
1001 AA 34 2343
1001 BB 60 1000
1001 BB 62 2346
1002 BB 34 1600
1002 CC 68 1700
I want the sample output in this form as shown in the below
**BranchId | AA_Cash | AA_Credit | BB_Cash | BB_Credit | CC_Cash | CC_Credit**
1000 ?
1001
1002
? = I need sum of Cash and Credit in each branches
select * from
(select bid, GroupCode, Cash FROM dueList) as T
PIVOT (sum(Cash) for GroupCode in([AA_Cash],[BB_Cash],[CC_Cash])) PT
This SQL is give output but only cash column, I need add credit column set to the output.
I try using following link
In Sql Server how to Pivot for multiple columns
but in my database there are only 16 branches. Once I try samples in above link it display duplicate lines for branches and lots of null in number area.