Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Create new record on two related tables with SQL7


Message #1 by "Hubert" <dasp@m...> on Mon, 20 Nov 2000 16:56:18 -0000
HI



I have to create a record on two database table on MS-SQL7



My problems is that to create the record on the second table, I need to

know the ID of the first (new record). But I don't know the ID of the new

record



Is there a easy way to do this ? May be even with a stored procedure ?

Message #2 by "Dallas Martin" <dmartin@z...> on Mon, 20 Nov 2000 19:30:29 -0500
ASP Code



' two SQL statements within one

sql = :INSERT myTable (fld1,fld2,fld3) VALUES (1,2,3); SELECT @@IDENTITY as

ID;"



' execute the code

set rs = Conn.Execute(sql)



' grab the identity

identity = rs("ID")



'use it in next insert

sql = "INSERT myOtherTable (FK_id,fld1,fld2) VALUES (" & id & "," + .......)



' insert the newly acquired ID into dependent table

Conn.Execute(sql)



You can achieve the same results using a Recordset object and a stored

procedure





----- Original Message -----

From: "Hubert" <dasp@m...>

To: "ASP Databases" <asp_databases@p...>

Sent: Monday, November 20, 2000 11:56 AM

Subject: [asp_databases] Create new record on two related tables with SQL7





> HI

>

> I have to create a record on two database table on MS-SQL7

>

> My problems is that to create the record on the second table, I need to

> know the ID of the first (new record). But I don't know the ID of the new

> record

>

> Is there a easy way to do this ? May be even with a stored procedure ?

>


  Return to Index