我有一个SQL查询,如果结果是Null,我正在尝试返回“0”。
到目前为止,我已经尝试过:
SELECT NULLIF (Amountt, '0') AS count
FROM 1Table
WHERE (Operations_Day BETWEEN @startdate AND @enddate) AND (location = @Storenumber) AND (Hour = '18')
SELECT ISNULL(Amountt, 0) AS count
FROM 1Table
WHERE (Operations_Day BETWEEN @startdate AND @enddate) AND (location = @Storenumber) AND (Hour = '18')
SELECT CASE WHEN (Amountt IS NULL) THEN 0 ELSE Amountt END AS count
FROM 1Table
WHERE (Operations_Day BETWEEN @startdate AND @enddate) AND (location = @Storenumber) AND (Hour = '18')
所有结果都返回一个BLANK字符串,在VB.net中处理不好如何返回“0”
答案 0 :(得分:0)
这意味着Amountt
不是NULL
。请尝试使用case
代替:
select (case when Amountt is null or Amountt = 'NULL' or Amountt = '' then 0 else Amountt end)
如果情况是您的代码返回 no 行,那么您可以使用聚合:
SELECT COALESCE(SUM(Amountt), '0') AS count
FROM 1Table
WHERE (Operations_Day BETWEEN @startdate AND @enddate) AND
(location = @Storenumber) AND (Hour = '18');