I have a float column, call it money.
I am trying to insert the 0 value as 0 and the empty string value should be NULL
INSERT INTO t1 (money) values ('0.00')
INSERT INTO t1 (money) values ('')
SELECT * FROM t1
This is the result I am trying to achieve
money
0
NULL
I tried Using an INSTEAD OF INSERT trigger (I used '123' just to visualize which condition is met)
iif(CAST(money AS nvarchar) = '', NULL, iif(money < '0.0001', '123', money))
SELECT * FROM t1
money
123
123
So it seems that I cannot compare my float column against an empty string.
But when trying following it looks like in fact it is possible:
CASE WHEN (money = '' THEN '456' ELSE iif(money < '0.0001', '123', money))
SELECT * FROM t1
money
456
456
Which makes me very unsure of how SQL Server converts those datatypes internally.
moneyfield in your table set toNOT NULL? Because if you have other columns and this one is not set toNOT NULL, then just don't include it on the insert...INSERT INTO t1 (money) values (NULL)or `INSERT INTO t1 (money) values (case when '' = '' then null else '')