Reputation: 68912
I have a SQL Server View
, and It has a field like this ISNULL(co.[MyValue],0) AS MyValue
in the select.
MyValue
in its table is a Nullable field, now I want to return 0
if the value is null but keep the field Nullable.
I want this because I don't want to change the Entity Framework EDMX file which has this view field as Nullable field.
Is there a way to do that in SQL?
Upvotes: 1
Views: 72
Reputation: 3716
Try this way, that I just used CASE WHEN
here, and it is as simple as you can see, I don't think any other explanation will be needed here.
SELECT CASE
WHEN Table_Name .[MyValue] IS NULL THEN 0
ELSE Table_Name .[MyValue]
END
FROM Table_Name
Upvotes: 0
Reputation: 15071
Use a CASE
statement
SELECT CASE
WHEN [MyValue] IS NULL THEN 0
ELSE [MyValue]
END
FROM yourtable
Upvotes: 1