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 ?
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 ?
>