1

Please tell me whats wrong with the query. I am using Pro C.

EXEC SQL SELECT 1
        INTO    :db_count
        FROM    sachin t
        WHERE   t.serialno =   :serial_no
        AND     t.amount = (:db_inamount - (SELECT NVL(overrun_amount,0)
                                            FROM  sunny tovrun
                                            WHERE tovrun.serialno = :serial_no
                                            AND   tovrun.timestamp = t.timestamp
                                            AND   rownum < 2)
                            )
        AND     t.request_code = 11
        AND     t.reason_code = 0
        AND     t.reversed    = 0
        AND rownum < 2;

And getting the compilation errors

Syntax error at line 4487, column 42, file my_file.pc:
Error at line 4487, column 42 in file my_file.pc            AND             t.amount = (:db_inamount - (SELECT NVL(overrun_amount,0)
5
  • 3
    What about using AND t.amount = (SELECT :db_amount - NVL(overrun_amount, 0) ... Commented Dec 30, 2009 at 6:58
  • Man db_amount is a variable and not a column name Commented Dec 30, 2009 at 7:05
  • I'm aware of that, I'm suggesting a computed column Commented Dec 30, 2009 at 7:07
  • @OMG, It worked. Could you please explain me the teason behind this Commented Dec 30, 2009 at 7:16
  • 1
    Try to give more informative titles than "Compile time Error in <programming language>". Commented Oct 23, 2011 at 22:04

1 Answer 1

2

Use:

 AND t.amount = (SELECT :db_amount - NVL(overrun_amount, 0) ...

It's a standard computed column, where the value is calculated prior to the comparison to the t.amount value for equality.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes thats true, but I want to know why AND t.amount = (SELECT :db_amount - NVL(overrun_amount, 0) worked and (:db_inamount - (SELECT NVL(overrun_amount,0) from table ) doesnot.
The latter is a scalar subquery expression, which was introduced back in 8i. But those 'modern' features aren't understood by the SQL parser in the pre-compiler. OMG's solution is a simpler subquery syntax supported since wayback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.