Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2003
    Posts
    81

    Unanswered: If Statement Syntax Problem

    I have the following code:


    SELECT
    A,
    IF B > C
    (SELECT B)
    ELSE
    (SELECT C),
    D
    FROM MyTable


    A, B, C and D are integer columns in MyTable.
    I get "incorrect syntax near the keyword 'IF' "
    I'm playing with parentheses but I can't get it to work.
    What's wrong with my syntax??

    Thanks,

    Bjorn

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    Which database software are you using ?

  3. #3
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Oracle -

    select a, (case WHEN B > C THEN B ELSE C END)
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  4. #4
    Join Date
    Jan 2003
    Posts
    81
    I use Microsoft SQL. I got it to work with the CASE statement.

    Thanks,

    Bjorn

  5. #5
    Join Date
    Feb 2002
    Posts
    2,232
    That is what I thought. Next time you would be better off posting your question to the database forum you are using.

Posting Permissions

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