Reputation: 35
I'm trying to do a SELECT
in which if the CurrencyCode
is = '', then I would like the result to be return as NULL
.
For example:
INSERT INTO Currency (CurrencyCode, CurrencyName)
SELECT
CurrencyCode,
CASE
WHEN CurrencyCode = ''
THEN NULL
END
FROM Contract
Can it be done?
Upvotes: 0
Views: 16367
Reputation: 7301
There are two possibilities either you use CASE WHE... THEN... ELSE... END
OR NULLIF
SELECT CurrencyCode,
NULLIF(CurrencyCode,''),
CASE
WHEN CurrencyCode = ''
THEN NULL
ELSE CurrencyCode
END
FROM Contract
Upvotes: 5