I want my sum function to return '0', if a value does not exist, Can anyone identify if there is a problem with the following SQL command. I have changed the order of the coalesce but this has not made a difference
SqlCommand scGetPostings = new SqlCommand(@"
SELECT
D1.dr,
D1.cr,
D1.asset_no,
(open_bal + dr - cr) AS closing_balance
FROM (SELECT
COALESCE(SUM(dr_amount), 0) AS dr,
COALESCE(SUM(cr_amount), 0) AS cr,
asset_no
FROM posting, sysasset
WHERE posting.asset_no = @AssetNumber
AND period >= asset_open_per
GROUP BY asset_no) AS D1, asset
WHERE D1.asset_no = asset.asset_no", DataAccess.AssetConnection);