Subject Re: [firebird-support] Help with Queries
Author Helen Borrie
At 08:26 AM 26/06/2004 +0000, you wrote:
>Using Firebird 1.5 & BCB 5.0
>
>What is the best/simplist way to accomplish these things.
>(My searching found results on UPDATE,

>FETCH

isn't available in DSQL

>& REPLACE INTO,

isn't supported.

>but no
>exact examples of what I want to accomplish)
>
>1) I have a table with 15 columns & 256 rows, col 1 is the PK, .
> I want to update all the columns (except the PK) in row x after a
>select from row y.
> i.e. copy a row to another row

Assuming in both cases you are using generator + trigger to poplulate the PK:

insert into table1 (col2, col3, col4, .....)
select col2, col3,col4, ... from table1
where blah...


>2) As above but with x & y being a range e.g. y = 1 to 20 & x = 51
>to 71 i.e. copy 20 rows.

exactly the same, just a different WHERE clause in the query


>3) As 1 & 2 above but with with the source & destination rows
>belonging to tables in a different database.

You can't do this directly. You'll need a connection for each database and
to start a single transaction spanning both connections. How (or IF) you
can do this depends on the data access components you're using. Select the
set from database a into a dataset then use a parameterised INSERT
statement to add the rows to the table in the other database, i.e. the
client has to mediate.

The datapump tool in IB_SQL uses this technique and allows you to massage
the data en route if needed. It uses the IB Objects TIB_DataPump component
so you can write an application to do the same thing.

/heLen