Tim Mullady
asked on
SQL Case statement not return under FALSE
Any ideas why the Else condition is not returning the [Parse_Row2] value? It does return the True condition but not the False condition.
,Case When [Parse_Row4] is not null
Then [Parse_Row4]
Else [Parse_Row2]
End
,Case When [Parse_Row4] is not null
Then [Parse_Row4]
Else [Parse_Row2]
End
Just a thought.. ISNULL([Parse_Row4], [Parse_Row2]) does the same thing.
And of course slightwv is correct regarding...
And of course slightwv is correct regarding...
- empty strings ' ', which are still a value, different from NULL which is the absence of a value.
- Give us your full T-SQL statement and some sample data.
the easiest way is to compare the field values side by side:
what's your expected result for the False condition?
could the False condition returns the same value as True condition as well? like NULL, etc?
[Parse_Row4] , Parse_Row2] ,
Case When [Parse_Row4] is not null Then [Parse_Row4] Else [Parse_Row2] End
what's your expected result for the False condition?
could the False condition returns the same value as True condition as well? like NULL, etc?
I tend to agree with the experts above in so much as checking for NULL is often not enough.
I would be inclined to check LEN
ie case when len(isnull(Parse_ROW4,'')) > 0 then Parse_ROW4 else Parse_ROW2 end as result
Just to test....
I would be inclined to check LEN
ie case when len(isnull(Parse_ROW4,''))
Just to test....
create table #EE_TEST (Parse_ROW4 varchar(20), Parse_ROW2 varchar(20))
insert #EE_TEST values (null,'2a')
insert #EE_TEST values ('4b','2b')
insert #EE_TEST values (' ','2c')
select Parse_ROW4, Parse_ROW2, len(Parse_ROW4) as Len_Parse_ROW4,
case when len(isnull(Parse_ROW4,'')) > 0 then Parse_ROW4 else Parse_ROW2 end as result
from #EE_TEST
Or, am I missing something else ? It almost sounds like it is only ever returning the TRUE condition, meaning Parse_ROW4 is never null.... In which case are there other conditions in you query that *might* be impacting your case condition.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Don't confuse empty strings as nulls. Possibly: Case When trim([Parse_Row4]) is not null
We'll need more information. Sample data and expected results would help a LOT!