Reputation: 4467
I have parameter and i want to check if length is 0. If it is 0 then Null, else I want the same value ? What idea do you have ?
SET @gre = NULLIF(LEN(@gre), 0)
Upvotes: 1
Views: 75
Reputation: 4360
Please try:
SET @gre =
case
when LEN(@gre) = 0 then NULL
else @gre
end
Upvotes: 0
Reputation: 56735
This should work if it's a VARCHAR:
SET @gre = NULLIF(@gre, '')
Upvotes: 3
Reputation: 3400
Use a CASE
statement:
SET @gre = CASE WHEN LEN(@gre) = 0 OR @gre IS NULL THEN NULL ELSE @gre END
Upvotes: 0