Subject | Re: SQL problem |
---|---|
Author | stanw1950 |
Post date | 2003-08-28T17:09:30Z |
What is the actual problem? This procedure looks like it should work
fine (if some missing variable colons are added). I can't think of a
better way to do this.
Stan Walker
--- In IBObjects@yahoogroups.com, "John Costanzo" <strtline@a...>
wrote:
fine (if some missing variable colons are added). I can't think of a
better way to do this.
Stan Walker
--- In IBObjects@yahoogroups.com, "John Costanzo" <strtline@a...>
wrote:
> Hello, I realize this is not an IBO problem but thought with allthe
> SQL people in the group it mught be a good place to ask thisquestion.
>1st
> I have the following situation. I need to loop through a table,
> select matching rows from another table based on a column in the
> table, then update some colukmns in the 1st table based onI
> calculations. This is what I cam up with:
>
> CREATE PROCEDURE TEST
> AS
> DECLARE VARIABLE COLAVAR SMALLINT;
> DECLARE VARIABLE COLBVAR NUMERIC(18,2);
> DECLARE VARIABLE COLCVAR NUMERIC(18,2);
> BEGIN
> FOR SELECT COLA
> FROM TABLE1
> INTO COLAVAR
> DO
> BEGIN
> SELECT SUM(COLB),Sum(COLC)
> FROM TABLE2
> WHERE (COLA = :COLAVAR)
> INTO :COLBVAR,:COLCVAR;
> UPDATE TABLE1
> SET COLX = :COLBVAR - COLCVAR
> WHERE COLA = :COLAVAR;
> END
> END #
>
> The FOR SELECT works fine. The SELECT SUM works fine. The problem
> have is with the UPDATE. It seems to me that since I am alreadya
> in a FOR SELECT loop there should be a way to update the currently
> selected row without the need to reselect. The documentation shows
> statement WHERE CURRENT OF cursor. This seems what I need but Itit
> gives me an error. Is there another way or is the way I am doing
> correct. I am using Delphi7, Firebird, and IBO. Thanks in advance.
> Geno