Subject Re: update from 2 tables
Author cbll_lam
> what about
> update a set a.p=(select b.q from b where b.y=a.x);
> Alan

I did not try but it looks strange. Does it actually work?

> > ... hence the non standard syntax from Access.
> >
I checked again, I used that syntax in MS SQL Serser not FB.
As SQL Server has it root from sybase, I googled and found that it is
also supported, but must turn ansi compliance off.

http://www.ianywhere.com/developer/product_manuals/sqlanywhere/0901/en/html/dbrfen9/00000498.htm

> > In a normalised structure, it would be a very unusual query to have
> > to run. Normally you would never have a field of B duplicated into
> > table A, but rather define a foreign key and join when applicable.
> >

Yes, I use un-normalised structure for efficiency and reporting.

> > If for some reason beyond my comprehension you needed to do it, the
> > easiest way to do it in Firebird is to use a stored procedure.
> >
> > ---
> >
> > set term ^ ;
> > create procedure copythis
> > as
> > begin
> > for
> > select q, y
> > from b
> > into :q, :y
> > do
> > begin
> > update a set p = :q where x = :y;
> > end
> > end
> > ^
> >
> > set term ; ^
> > commit;
> > execute procedure copythis;
> > commit;
> >

Thank you! I will try later because I've never used SP in FB before.

regards,
bill