🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #2071

Accessing highest auto number

#2071
From: Simon Elliott
Date: Tue, 02 Dec 2003 17:26
21 lines
1836 bytes
I have two tables, let's say table1 and table2.

table1 has an auto number primary key table1key. 

I populate table1 with a TADOQuery parameterised SQL append query,
omitting the table1key field so that the auto number filed is populated
automatically. So far so good.

table2 has its own primary key, but also needs table1key as a foreign
key to link table1 and table2. I can populate the other fields of table2
with a TADOQuery parameterised SQL append query, but I'm not sure of the
best way of setting the value of table1key.

I suppose I can query table1 to get the value of table1key from the
record I've just added, and use this as a parameter in my append query
to add the corresponding records to table2, but this seems a bit long
winded. Is there any SQL magic or other more elegant way of getting at
this value? 
-- 
Simon Elliott
http://www.ctsn.co.uk/
Technical Details
Message-ID: <vIB+nCAzsMz$IwBT@courtlands.demon.co.uk>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!newsgroups.borland.com!courtlands.demon.co.uk!simon

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,3afd7f6873225c1f,start
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-12-02 09:34:56 PST
Message-ID: <vIB+nCAzsMz$IwBT@courtlands.demon.co.uk>
Date: Tue, 2 Dec 2003 17:26:11 +0000
From: Simon Elliott <simon@nospam.demon.co.uk>
Reply-To: Simon Elliott <news@nospam.demon.co.uk>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Accessing highest auto number
Lines: 27
Organization: Courtlands Technical Services
MIME-Version: 1.0
X-Newsreader: Turnpike Integrated Version 4.02 U <aLIvuQCpEWZ0Tu7eytpxRhrSSE>
NNTP-Posting-Host: 158.152.154.121
X-Trace: newsgroups.borland.com 1070385983 158.152.154.121 (2 Dec 2003 09:26:23 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!newsgroups.borland.com!courtlands.demon.co.uk!simon