Put '0' when there is a null value in sql view

JohnDW

Well-known member
Joined
Jun 13, 2012
Messages
60
Location
Antwerp, Belgium
Programming Experience
1-3
Hello,

I have a view in sql server. ViewInkPermndLing2.
The Query for ViewInkPermndLing2 :
VB.NET:
SELECT     Month(Datum), 
SUM(CASE WHEN Year(Datum) = 2012 THEN Som END) As [Year2012]
FROM         dbo.ViewInkPermndLing1
GROUP BY Month(Datum)

Is there a way to put a 0 (number as integer), instead of the null values
when there's no data in the query above (from view ViewInkPermndLing2). I need that view to calculate in the datagridview that
is filled with that view (ViewInkPermndLing2).

THanks,

John
 
Txs,

But where do I plase that evalution,
I suppose it must be something like:

VB.NET:
 Iff(SUM(CASE WHEN Year(Datum) = 2012 THEN Som END) As [Year2012],0)

But this doesn't work.

John
 
Why would be something like that? The one thing I said was to use ISNULL and there's no ISNULL in your code. Where do you want the value that comes from that expression? That's where you put the expression.
 
Hello,

I have a view in sql server. ViewInkPermndLing2.
The Query for ViewInkPermndLing2 :
VB.NET:
SELECT     Month(Datum), 
SUM(CASE WHEN Year(Datum) = 2012 THEN Som END) As [Year2012]
FROM         dbo.ViewInkPermndLing1
GROUP BY Month(Datum)

Is there a way to put a 0 (number as integer), instead of the null values
when there's no data in the query above (from view ViewInkPermndLing2). I need that view to calculate in the datagridview that
is filled with that view (ViewInkPermndLing2).

THanks,

John
I believe the SUM() function treats null's as 0 already, but in the event it doesn't:
VB.NET:
SUM(CASE WHEN Year(Datum) = 2012 THEN [COLOR="#B22222"]IsNull(Som, 0) ELSE 0[/COLOR] END) As [Year2012]
 
I get the following Error:
SQL Execution Error:
Execution Statement :
SELECT TOP (100) PERCENT MONTH(Datum) AS Month,
Iff(SUM(CASE WHEN Year(Datum) = 2012 THEN Som END) AS [Year2012],0)
FROM dbo.ViewInkPermndUnd1
GROUP BY MONTH(Datum)


Error Source: .Net sqlClient Data Provider
Error Message: Incorrect syntas near ','.

John
 
I get the following Error:
SQL Execution Error:
Execution Statement :
SELECT TOP (100) PERCENT MONTH(Datum) AS Month,
Iff(SUM(CASE WHEN Year(Datum) = 2012 THEN Som END) AS [Year2012],0)
FROM dbo.ViewInkPermndUnd1
GROUP BY MONTH(Datum)


Error Source: .Net sqlClient Data Provider
Error Message: Incorrect syntas near ','.

John
Are you even reading any of our replies? Or are you off in your own world?

I suspect the latter.
 
Back
Top