I want to get NULL values instead of zero in my query.I put a condition where the varchar '0.0000' is not supposed to display along with NULL value. When the outcome comes, NULL is not displayed but 0.0000 is still showing there. Is there anyway i can convert that varchar to NULL so that the value is not displayed?
Asked
Active
Viewed 1,669 times
0
-
3Please show what query have you written – Hitesh Jun 13 '14 at 12:38
-
1Is the column in your table nullable? – Jens Jun 13 '14 at 12:39
2 Answers
3
You can use NULLIF
:
Returns a null value if the two specified expressions are equal.
SELECT NULLIF(Column, '0.0000') As Column
FROM dbo.TableName

Tim Schmelter
- 450,073
- 74
- 686
- 939
-
@Patrick: "Is there anyway i can convert that varchar to NULL?" So he wants to treat the varchar `'0.0000'` as `NULL`. – Tim Schmelter Jun 13 '14 at 12:41
-
1
-
-
1@PatrickHofman - are you perhaps thinking of `ISNULL`/`COALESCE`? That's not what Tim's recommending. – Damien_The_Unbeliever Jun 13 '14 at 12:43
-
@Damien_The_Unbeliever: You are right, my bad. Tim: my apologies. – Patrick Hofman Jun 13 '14 at 12:44
1
select case when your_column = '0.0000' then null
else your_column
end as your_column
from your_table

juergen d
- 201,996
- 37
- 293
- 362
-
Thank you all for your answer. For me, the one with Select CASE worked. – user3737628 Jun 13 '14 at 13:10