We help IT Professionals succeed at work.

Help with query

206 Views
Last Modified: 2014-05-14
Hello, I have the following example data where I need the result set to look like this

Branch ID | Deposit Total | Loan Total | Other Total

    1                  2694.00            1238.00          3324.00    

What is the best method to accomplish this task using the example data below?


CREATE TABLE #Data
(
       AccountID int NOT NULL PRIMARY KEY
      ,BranchID int NOT NULL
      ,AccountBalance money NULL
      ,ProductType varchar(10) COLLATE DATABASE_DEFAULT NOT NULL
)

insert #Data(AccountID, BranchId, AccountBalance, ProductType) values (1, 1, 1000.00, 'Loan')
insert #Data(AccountID, BranchId, AccountBalance, ProductType) values (2, 1, 238.00, 'Loan')
insert #Data(AccountID, BranchId, AccountBalance, ProductType) values (3, 2, 566.05, 'Loan')

insert #Data(AccountID, BranchId, AccountBalance, ProductType) values (4, 1, 2583.00, 'Deposit')
insert #Data(AccountID, BranchId, AccountBalance, ProductType) values (5, 1, 111.00, 'Deposit')
insert #Data(AccountID, BranchId, AccountBalance, ProductType) values (6, 3, 200.00, 'Deposit')


insert #Data(AccountID, BranchId, AccountBalance, ProductType) values (7, 1, 22.00, 'Other')
insert #Data(AccountID, BranchId, AccountBalance, ProductType) values (8, 1, 3258.00, 'Other')
insert #Data(AccountID, BranchId, AccountBalance, ProductType) values (9, 1, 44.00, 'Other')
Comment
Watch Question

Senior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Yes, this will work great! Thank you!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.