I have an SQL query where i'm trying to return a "0" if the result is Null.
So far I have tried:
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')
All results return a BLANK string, which is not handled well in VB.net How can I return "0"
That means that
Amountt
is notNULL
. Try using acase
instead:If the situation is that your code is returning no rows, then you can use aggregation: