0

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);
1
  • Please remove the C# code, as it seems to be a pure SQL question. And put the query with a descent formatting (indentation and line breaks) Commented Jan 22, 2013 at 10:55

3 Answers 3

2

You should use ISNULL function for the statement:

ISNULL(open_bal + dr - cr, 0.0) as closing_balance
Sign up to request clarification or add additional context in comments.

Comments

1
(ISNULL(open_bal, 0.0) + ISNULL(dr, 0.0) - ISNULL(cr, 0.0)) as closing_balance

Comments

0

Try :

nvl(open_bal + dr - cr, 0.0) as closing_balance

sql_isnull

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.