0

我需要一些关于 SQL 语句的帮助,此时以下 SQL 语句有效,但我想添加 if closing_balanceis null 将值设置为 0.00

是否可以将此添加到以下语句中:

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);
4

3 回答 3

2

您应该对语句使用ISNULL函数:

ISNULL(open_bal + dr - cr, 0.0) as closing_balance
于 2013-01-22T10:56:48.430 回答
1
(ISNULL(open_bal, 0.0) + ISNULL(dr, 0.0) - ISNULL(cr, 0.0)) as closing_balance
于 2013-01-22T11:05:26.820 回答
0

尝试 :

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

sql_isnull

于 2013-01-22T11:15:37.710 回答