SQL CASE Statements with IF EXISTS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramdiane
    New Member
    • Jun 2007
    • 2

    SQL CASE Statements with IF EXISTS

    Hello,

    I was hoping that somebody would kindly help me with this question..

    I know this may be very basic for you guys/girls in here..

    I need to select a field "A" only if it has a value that exists, if not select a field "B"

    So i am going along the lines of:

    SELECT
    x,
    y,
    z,
    CASE WHEN IF EXISTS "A" THEN "A"
    ELSE "B"

    FROM TABLE 1234567

    Can anyone help please?
  • tifoso
    New Member
    • Apr 2007
    • 41

    #2
    I guess when you say if it exists you mean there is a value, the field itself always exists.yoyu don't say if A is a string or numeric so can't give you more than this

    select f1,f2,
    CASE WHEN A is not null then A ELSE B END
    from wacked_table

    Ciao

    Comment

    • ramdiane
      New Member
      • Jun 2007
      • 2

      #3
      THANKS FOR THAT...

      It was easier than i thought it was...

      i just need to use the brain a bit more and think of simpler solutions

      Thank you

      Comment

      Working...