If Statement not working

  • I'm trying to write this select statement it will run without the if statement but once I put the if statement it will not run.

    What I'm trying to do is have the query run with all Doc after 9/30/2009 and with Current Transaction Amt is > 0 and Transaction Amt is >= the Current Transaction Amt. Then If the Transaction Amt is = Current Transaction Amt then set the Current Transaction Amt to 0.

    SELECT DOCDATE, POSTDATE, DOCNUMBR,

    CURNCYID, TRXAMT, CURTRXAM

    FROM CUSTCARD

    WHERE (DOCDATE > '9/30/2009') AND (CURTRXAM > '0') AND

    (TRXAMT >= CURTRXAM) and

    IF TRXAMT = CURTRXAM

    set CURTRXAM = '0

    Thanks for your help

  • You cannot use IF in a DML statement. You should use a CASE expression.

    Example:

    case when TRXAMT = CURTRXAM then 0 else CURTRXAM end

  • I received this error msg when I put in that case statement "An expression of non-boolean type specified in a context where a condition is expected, near 'end'."

  • kbnyny (7/6/2010)


    I received this error msg when I put in that case statement "An expression of non-boolean type specified in a context where a condition is expected, near 'end'."

    Since you didn't post the actual code the received the error, you will have to debug that yourself.

    I suggest you read about how to use CASE in SQL Server Books Online.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply