Board index » delphi » SQL Update Help Required

SQL Update Help Required

I know it's simple. I did it before when I used Oracle for a few months
back in about 1987.

Paradox DB Tables. Delphi 2.0.

How do I update a field in one table based on the contents of another.

eg TableA has a number of fields including FieldX and FieldY

TableB has a two fields - FieldX and FieldY.

I want to update the value of FieldY in TableA with the value of FieldY
in TableB in the row where FieldX matches that in TableA

a more diagrammatic example:

Before my update query:

TableA
======

TableB
======
FieldA     FieldB
======     ======
AAA        PPP
BBB        QQQ
CCC        RRR

and after my query, what I want is

TableA
======
PK   FieldA     FieldB
==   ======     ======
01   AAA        PPP
02   BBB        QQQ
03   CCC        RRR
04   AAA        PPP

I can do it easily with QBE. I know it's easy with SQL. Please Help!
--
Tim Stannard -  Ad Hoc Computing, Addlestone, Surrey, UK
                e-mail: stann...@adhoc.demon.co.uk

 

Re:SQL Update Help Required


Tim Stannard <T...@adhoc.demon.co.uk> wrote in article
<1lNXVOA$WyLyE...@adhoc.demon.co.uk>...

Quote
> Paradox DB Tables. Delphi 2.0.

> How do I update a field in one table based on the contents of another.

> eg TableA has a number of fields including FieldX and FieldY

> TableB has a two fields - FieldX and FieldY.

> I want to update the value of FieldY in TableA with the value of FieldY
> in TableB in the row where FieldX matches that in TableA

I have not tried this, but it may help point you in a good direction.

Try using a TUpdateSQL Component with the UPDATESQL property set as
follows:

Update TableA, TableB set TableA.FieldY = TableB.FieldY where TableA.FieldX
= TableB.FieldX

When you run this update query, it should update TableA.FieldY with the
contents of TableB.FieldY

Let me know when you get this to work.  I would like to know what
obstacles, if any, you encountered in your path.

Good Luck,

Yaron
ypa...@missionware.com

Other Threads