SELECT using IF statement
Results 1 to 4 of 4

Thread: SELECT using IF statement

  1. #1
    Member
    Join Date
    Mar 2013
    Posts
    32

    SELECT using IF statement

    Hi, all.

    Is this possible, I am trying to include an IF statement in my SELECT query like.

    In place of displaying the content of "Fail" I want to display text.

    Code:
    SELECT SeqID, SeqText,  IF(Fail = 1,Fail = "Failed")
    FROM Avail, Table01Q
    WHERE Avail.UniqueID = "' . $_SESSION['UniqueID'] . '"',$prop);
    Many thanks in advance.

    Blackbox

  2. #2
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    IF() requires three arguments.

    Also, why compare Fail twice anyway? If the value was 1, then you already know the value is not "Failed". Or are you trying to update the value (you cannot)?

  3. #3
    Member
    Join Date
    Mar 2013
    Posts
    32
    Hi traq,

    Many thanks for your reply.

    what I want to do is, if Fail = 1, then instead of outputting 1, output "Failed. Or if Fail = 2, output Pass.

    I know I can do this with a php if statement but in this case I am outputting to a PDF using FPDF and PDF_MySQL_Table.

    The code to output the query is:

    Code:
    $pdf->Table('SELECT SeqID, SeqText,  Fail 
    FROM Avail, Table01Q
    WHERE Avail.UniqueID = "' . $_SESSION['UniqueID'] . '"',$prop);
    Is it not possible to code it so it out puts "Fail" or "Pass".

    Again, many thanks for your time.

    Blackbox

  4. #4
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    SQL is not PHP.
    (did you see my link to the docs, above?)

    Sounds like you want something like
    Code:
    SELECT SeqID, SeqText, IF( Fail=1, 'Fail', 'Pass' ) as Fail
     …

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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