Reputation: 1063
I need some help with a SQL statement, at the minute the following SQL statement works, but I want to add if closing_balance
is null set the value to 0.00.
Is there away to add this to the following statement:
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);
Upvotes: 0
Views: 111
Reputation: 2880
(ISNULL(open_bal, 0.0) + ISNULL(dr, 0.0) - ISNULL(cr, 0.0)) as closing_balance
Upvotes: 1
Reputation: 405
You should use ISNULL function for the statement:
ISNULL(open_bal + dr - cr, 0.0) as closing_balance
Upvotes: 2