Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    14

    Unanswered: Nesting case in if...else?

    Hello;

    Is it possible to nest a case statement inside of an if...else statement? I can't seem to get this to work, and I can't seem to find an alternative solution. For example, I'd like to do something like this (this is a snippet of my SQL statement):
    Code:
    FieldAliasName =
          if (TABLE1.field1 = NULL)
              case TABLE2.field1
              when '' then TABLE2.field2
              else TABLE2.field3
          else
              TABLE1.field1
    end,
    In English...

    If the value of TABLE1.field1 is NULL, then use the value from TABLE2.field2 unless it is empty, then use TABLE2.field3.
    Sincerely,
    Todd M. Taylor
    http://www.toddtaylor.com/

  2. #2
    Join Date
    Oct 2003
    Posts
    41

    Re: Nesting case in if...else?

    You can do something like this:
    FieldAliasName = case when TABLE1.field1 is Null
    then
    case when TABLE2.field1=''
    then TABLE2.field2
    else TABLE2.field3
    end
    else TABLE1.field1
    end

    Originally posted by Blitzkrieg
    Hello;

    Is it possible to nest a case statement inside of an if...else statement? I can't seem to get this to work, and I can't seem to find an alternative solution. For example, I'd like to do something like this (this is a snippet of my SQL statement):
    Code:
    FieldAliasName =
          if (TABLE1.field1 = NULL)
              case TABLE2.field1
              when '' then TABLE2.field2
              else TABLE2.field3
          else
              TABLE1.field1
    end,
    In English...

    If the value of TABLE1.field1 is NULL, then use the value from TABLE2.field2 unless it is empty, then use TABLE2.field3.

  3. #3
    Join Date
    Oct 2003
    Posts
    14

    Re: Nesting case in if...else?

    Thanks rmpathak, that worked perfectly!
    Sincerely,
    Todd M. Taylor
    http://www.toddtaylor.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •