|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL Insert into Multiple Tables
Hi,
I'm currently working on a project for a company which at the end of this ASP Application it enters data from a 2 different forms into 2 tables in one database. I have one insert working correctly: Code:
sql_insert = "insert into tblIdentity (Prod_4digitSKU, IdentityID, IdentityName, IdentityBirth, GiftFrom, DateEntered) values ('" & BearSKU4Digit & "', '" & PersonalID & "','" & BearName & "', '" & BirthDate & "','" & GiftFrom & "', '" & HiddenDate & "')"
The other table (tblOwner) has these columns, OwnerID(AutoNumber), OwnerAddress, OwnerCity, OwnerCountry, OwnerEmail, OwnerPhone, OwnerBirth, MailingList(YES/NO), IndentityID (This is the foreign key for the intial table above. How can I be able to insert this data into 2 tables in one INSERT SQL Statement. I thought I could independantly do this, but fails. Pl,ease HELP ME!! ![]() |
|
#2
|
||||
|
||||
|
Quote:
You can't do it with one statement. You need a sql statement for each table. Example: Code:
Insert into the first table strSql = "INSERT INTO Table1 VALUES(blah, blah)" Conn.Execute(strSql) Insert into the second table strSql = "INSERT INTO Table2 VALUES(blah, blah)" Conn.Execute(strSql) |
|
#3
|
|||
|
|||
|
Quote:
Would this mean I would have the these sql statements after each other with strSQL as the same?? This has been driving me up the wall all day |
|
#4
|
|||
|
|||
|
Quote:
What??? S- |
|
#5
|
|||
|
|||
|
As in strSQL = INSERT ... table1
then strSQL = INSERT ... table2 then I execute these statements, using the same connection obviously. I haven't tried this yet, but could possibly work? |
|
#6
|
||||
|
||||
|
you can execute more than one sql statement using the same connection. However, the way you have it written you are redefining strSQL before you run in. In this case, only the second SQL statement would execute. You could define it this way:
Code:
strSQL1 = ...... strSQL2 = ...... and then execute each one.. ..or.. ..do it just like Memnoch said: Quote:
|
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > SQL Insert into Multiple Tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|