Subject | Re: [ib-support] TRUNCATE TABLE |
---|---|
Author | Helen Borrie |
Post date | 2002-01-20T23:21:24Z |
At 04:14 PM 20-01-02 +0000, you wrote:
2. Write a stored procedure with a FOR loop (fast)
create procedure update_it
as
declare variable prod_id numeric(18,0);
declare variable x numeric(18,2);
declare variable y sometype;
declare variable z someothertype;
begin
for select product_id, sum(closing), col1, col2 from batch
group by product_id
into :prod_id, :x, :y, :z
do begin
UPDATE product
SET closing = :x,
col1 = :y,
col2 = :z
WHERE product_id = :prod_id;
end
end
Just ensure that all the columns selected from Batch can be aggregated by product_id.
regards,
Helen
All for Open and Open for All
Firebird Open SQL Database ยท http://firebirdsql.org
_______________________________________________________
>Hi,No. But scan the archive because I seem to recall Ann Harrison recently posted a suggestion for achieving it. 2 - 3 weeks ago, I think.
>
>Is there any equivalent command in FB for Truncating Table ?
>UPDATE product P1. Multiple correlated sub-selects on each column required (slow)
> SET closing = (select sum(closing) from batch B
> where B.product_id = P.product_id) ;
>
>How do we handle when we need to update one more column in the product table from
>table batch?
2. Write a stored procedure with a FOR loop (fast)
create procedure update_it
as
declare variable prod_id numeric(18,0);
declare variable x numeric(18,2);
declare variable y sometype;
declare variable z someothertype;
begin
for select product_id, sum(closing), col1, col2 from batch
group by product_id
into :prod_id, :x, :y, :z
do begin
UPDATE product
SET closing = :x,
col1 = :y,
col2 = :z
WHERE product_id = :prod_id;
end
end
Just ensure that all the columns selected from Batch can be aggregated by product_id.
regards,
Helen
All for Open and Open for All
Firebird Open SQL Database ยท http://firebirdsql.org
_______________________________________________________