Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    14

    Unanswered: need help implementing IF..ELSE

    Hi,

    im really now with sql so can anyone give an example on this problem?
    i dont know how to implement this kind of logic in sql:

    if (ID != null)
    print name
    else print "not available"

    i was thinking about using case, but i'm not sure how to implement printing a string in a case statement using sql
    sorry for the language term...i'm really used to java, so i always think in java term when im doing programming

    thanks

  2. #2
    Join Date
    Oct 2003
    Location
    Denver, Colorado
    Posts
    137
    In MySQL, you want to use a statement like:

    SELECT IF(ISNULL(ID), 'Not Available', Name), ...

  3. #3
    Join Date
    Dec 2003
    Posts
    14
    this is how i do it....

    SELECT IF(ISNULL("Student"."ID"),
    'Not Available',
    "Student"."LastName"),
    COMPUTER.SerialNumber "Serial Number"
    FROM COMPUTER left join Student
    ON "Student"."ID" = COMPUTER.ID
    ORDER BY COMPUTER.SerialNumber
    ;


    but it gives me this error:

    SELECT IF(ISNULL("PERSON"."PersonID"), 'Not Available', "PERSON"."LastName"),
    *
    ERROR at line 1:
    ORA-00904: "IF": invalid identifier


    What's wrong??????
    someone PLSSSS HELP

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    why are you getting an oracle error message from mysql?

    this is the mysql forum


    try this, it is standard sql and works in all databases that support standard sql --
    Code:
    select case when  is null
                then 'not available'
                else student.lastname
             end
         , computer.serialnumber as "serial number"
      from computer 
    left outer
      join student
        on computer.id = student.id
    order 
        by computer.serialnumber
    rudy
    http://r937.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
  •