question

richmondo avatar image
richmondo asked

Please I want to get the sum of total assets of these tables

SELECT 'ASSETS :' AS [Account Name],'Totals:' AS [$] UNION ALL SELECT COA.Account_Name AS 'ASSET',CAST(SUM(Debit-Credit)AS varchar)AS [$] FROM COA JOIN CashBook ON COA.Account_Name = CashBook.Account_Name WHERE COA.Account_Name IN ('Cash-in- Hand') GROUP BY COA.Account_Name UNION ALL SELECT COA.Account_Name AS 'ASSET',CAST(SUM(Debit-Credit)AS varchar)AS [$] FROM COA JOIN AccountReceivable ON COA.Account_Name = AccountReceivable.Account_Name WHERE COA.Account_Name IN ('Account Receivable') GROUP BY COA.Account_Name UNION ALL SELECT COA.Account_Name AS 'ASSET',CAST(SUM(Debit-Credit)AS varchar)AS [$] FROM COA JOIN Allowance ON COA.Account_Name = Allowance.Account_Name WHERE COA.Account_Name IN ('Allowance for Doubtful Account') GROUP BY COA.Account_Name UNION ALL SELECT '','------------' UNION ALL SELECT 'Total Assets',CAST(SUM(Debit-Credit) AS varchar) AS [$] FROM COA JOIN CashBook JOIN AccountReceivable JOIN Allowance ON COA.Account_Name = CashBook.Account_Name JOIN AccountReceivable.Account_Name JOIN Allowance.Account_Name WHERE COA.Account_Name IN ('Assets')
sql-server-2008
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Tim avatar image
Tim answered
Dump the results to a temporary table then do a sum of the values you need.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.