Reputation: 317
I have a mySQL query which under special circumstances returns the value "0" (not NULL) but number 0.
SELECT A.user_id as customerref
In this case I would like to return an empty value. What is the correct code for doing so.
Upvotes: 2
Views: 1904
Reputation: 12391
You can use CASE
for this:
SELECT
CASE
WHEN A.user_id = 0 THEN NULL
ELSE A.user_id
END AS customerref
Upvotes: 1
Reputation: 7986
With case
:
case when A.user_id = 0 then null else A.user_id end
Upvotes: 1
Reputation: 311188
You could use a case
expression:
CASE WHEN a.user_id != 0 THEN a.user_id END AS customerref
Upvotes: 4