Monday, February 20, 2012

Question on case

I am trying to run a query with a case statement in it. The column has some null values and I want to replace the null with a character string.
ex:
case my_column when null then 'char_string' else my_column end 'column'

I run it and the nulls are still in my_column. Does case not work on null values this way?
Thanks.Originally posted by exdter
I am trying to run a query with a case statement in it. The column has some null values and I want to replace the null with a character string.
ex:
case my_column when null then 'char_string' else my_column end 'column'

I run it and the nulls are still in my_column. Does case not work on null values this way?
Thanks.

Try this:

case when my_column is null then 'char_string' else my_column end 'column'|||Can I use an isnull here? Doesn't matter. Your solution worked. Thanks alot.|||Use isull(mycolumn,'CharString')|||Thats what I thought too but I used Snails method already.
Thanks.|||I tried it this way too and it works fine and is much neater.
Thanks.|||coalesce(mycolumn,'charstring') is also much neater and it uses standard sql

;)|||Thanks r937!

No comments:

Post a Comment