I have a little problem with the query I'm trying to develop.
Here's what my table looks like: -
Account Table
ClientNo AccountType Balance 1234 SUP1 25 1234 SUP1.1 35 1234 RET1 20 1111 SUP1 50 1111 DIS4 60
I am trying to get a result that looks like this: -
ClientNo TotSupBal TotSuppAccts TotRetBal TotRetAccts TotDisBal TotDisAccts 1234 70 2 20 1 0 0 1111 50 1 0 0 60 1
Essentially, a client can be in the account table many times, since there can be many accounts for each client.
Account types always start with the same characters to begin with, but depending on how many of these accounts the number can be something really, and subsequent accounts will always be decamenal, and then the number ... for example. the first SUP account is just SUP1, however the next SUP account will be SUP1.1, then SUP1.2, etc ...
I wrote the following query
SELECT ClientNo, SUM(Balance) AS TotSupBal, COUNT(AccountType) AS TotSuppAccts FROM Account WHERE (AccountType LIKE 'SUP1.%') OR (AccountType = 'SUP1') GROUP BY ClientNo
* The reason is that there are 2 different WHERE clauses, because I cannot just use SUP1%, since there are accounts like SUP12 that do not match SUP1.
This query works fine, however, it only lists the SUP account type. How can I create the same output, however in multiple columns for each type of account?
I am using Microsoft SQL 2008 R2