Subject Re: [ib-support] Beginner fiddeling with Stored Procedure
Author Helen Borrie
Kai:
At 10:32 PM 07-03-02 +0100, you wrote:

> UPDATE POST_EANSEND
> SET SISTESENDNR = NEWNUMBER // This is the offending line.

should be
SET SISTESENDNR = :NEWNUMBER

> WHERE ID = 1;
> SUSPEND;
>
>END
>
>The error message I'm getting is this: "Dynamic ... error code = -206 Column
>unknown NEWNUMBER At line 25, Column 21 (se my comment in the code for this
>line)

The rule I use when working with variables in SPs is this:

When your code refers to the variable, omit the ':'.
When it refers to the value stored in the variable, use the ':'.
In an SQL statement, always refer to the variable by its value, i.e.
:NEWNUMBER, so that SQL knows to treat it as a value and not an identifier.

Hence, this would work:

NEWNUMBER = :NEWNUMBER + 1

and these are wrong:

NEWNUMBER = NEWNUMBER + 1 (the engine looks for a column called NEWNUMBER)

:NEWNUMBER = :NEWNUMBER + 1 (you can't assign to a value, only to a variable)

But this is OK because it is testing a value:

if (:NEWNUMBER +1 > :MAXNUMBER) then .....

cheers,
Helen


All for Open and Open for All
Firebird Open SQL Database · http://firebirdsql.org ·
http://users.tpg.com.au/helebor/
_______________________________________________________