Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO w/ Multiple Tables 1

Status
Not open for further replies.

bobbyr

Programmer
Nov 30, 2000
66
0
0
US
I currently have 2 tables, TeamMember and Stats. The TeamMember table has a MemberId (AutoNumber), Name, and Number. The Stats table has the MemberId, Hits, HomeRuns, and Strikeouts fields. When I do an Insert Into for the TeamMember table, the MemberId is auto generated. How do I then Insert that MemberId into the Stats table to associate stats with the team member at the same time?
 
I think you might have to do the 2nd insertion manually. After a record is inserted in TeamMember table, do a Last function SQL query to get the last record in the table.

Something like this,

<CFQUERY NAME=&quot;LastTeamMemberRecord&quot;>
SELECT Last(MemberID) AS LastMemberID
FROM TeamMember;
</CFQUERY>

Use the LastMemberID value in this query in your second query that will do the insertion on the Stats table.

HTH,

Klotzki
 
Thank you very much. It worked perfect. The problem I was having was with the Last(MemberID) part.
 
I have the same question. The last id is not getting put into the table that I want. I also have two tables with autonumber , but I'm using Oracle. The tables are one for customer info and the other for computer info, I need to get the custid (the foreign key) put into computer info table. I used the example above , changed it with my db info and it is not working. Can you explain where to put the query. I put it before the insert query on the action page , but it didn't work.

thanks,
olmos
 
make sure it is not a sql problem (i guess it is). If it is, you're on the wrong forum !!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top