I am trying to create a subtotal that calculates the account numbers based on the first 2 digits.
Account ShortDesc LongDesc Balance
1000 Petty Cash Operating Cash 250.00
1001 Bradley Bank Checking Account 500.00
1100 Downey Bank Checking Account 200.00
1101 BoardmanFoods Bakery Department 150.00
1201 BoardmanFoods Bakery Department 130.00
1202 Petty Cash Operating Cash 400.00
SELECT Account, ShortDesc, LongDesc, Balance, SUM(Balance) OVER (partition by NULL) AS Subtotal FROM dbo.COA
WHERE Account LIKE '10%'
OR
Account LIKE '20%'
OR
Account LIKE '30%' OR
Account LIKE '40%'
I want the result to look like this:
Account ShortDesc LongDesc Balance Subtotal
1000 Petty Cash Operating Cash 250.00
1001 Bradley Bank Checking Account 500.00 750.00
1100 Downey Bank Checking Account 200.00
1101 BoardmanFoods Bakery Department 150.00 350.00
1201 BoardmanFoods Bakery Department 130.00
1202 Petty Cash Operating Cash 400.00 530.00
I would also like to have a Grand_Total field that calculates the grand total at the end of the query.
Account ShortDesc LongDesc Balance
1000 Petty Cash Operating Cash 250.00
1001 Bradley Bank Checking Account 500.00
1100 Downey Bank Checking Account 200.00
1101 BoardmanFoods Bakery Department 150.00
1201 BoardmanFoods Bakery Department 130.00
1202 Petty Cash Operating Cash 400.00
SELECT Account, ShortDesc, LongDesc, Balance, SUM(Balance) OVER (partition by NULL) AS Subtotal FROM dbo.COA
WHERE Account LIKE '10%'
OR
Account LIKE '20%'
OR
Account LIKE '30%' OR
Account LIKE '40%'
I want the result to look like this:
Account ShortDesc LongDesc Balance Subtotal
1000 Petty Cash Operating Cash 250.00
1001 Bradley Bank Checking Account 500.00 750.00
1100 Downey Bank Checking Account 200.00
1101 BoardmanFoods Bakery Department 150.00 350.00
1201 BoardmanFoods Bakery Department 130.00
1202 Petty Cash Operating Cash 400.00 530.00
I would also like to have a Grand_Total field that calculates the grand total at the end of the query.