Subject Re: [firebird-support] MAX function
Author Thomas Steinmaurer
Hi Tim,

> I need to get a field value value dependant on the maximum of another
> field value.
>
> For example in the following case, I want the BATCH NUMBER value for
> the maximum RECORDNO value.
>
> I have tried the following SQL, but I keep on getting an error
> message (TERMID is an input variable):
>
> FOR SELECT MAX(RECORDNO), BATCHNUM FROM BATCH
> WHERE
> TERMID = :TERMID
> GROUP BY BATCHNUM
> INTO
> :TRECORDNO, :TBATCHNUM
> DO
> BEGIN
> IF :TRECORDNO > :OLDRECNO THEN

From a syntactical POV, this should be:

IF (:TRECORDNO > :OLDRECNO) THEN


Btw, you only need the ':' in front of parameter, variables ... in SQL
statements, but not in assignments, IF conditions, ...



--
Best Regards,
Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database, MS SQL Server and
NexusDB V2
Upscene Productions
http://www.upscene.com