SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 6th, 2004, 08:08 PM
chris_vine chris_vine is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 37 chris_vine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 25 m 23 sec
Reputation Power: 5
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!!

Reply With Quote
  #2  
Old December 6th, 2004, 09:31 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,879 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 18 h
Reputation Power: 500
Quote:
Originally Posted by chris_vine
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.

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)

Reply With Quote
  #3  
Old December 6th, 2004, 11:16 PM
chris_vine chris_vine is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 37 chris_vine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 25 m 23 sec
Reputation Power: 5
Quote:
Originally Posted by Memnoch
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)

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

Reply With Quote
  #4  
Old December 7th, 2004, 12:40 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
Quote:
Originally Posted by chris_vine
Would this mean I would have the these sql statements after each other with strSQL as the same??



What???

S-

Reply With Quote
  #5  
Old December 7th, 2004, 01:50 PM
chris_vine chris_vine is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 37 chris_vine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 25 m 23 sec
Reputation Power: 5
Exclamation

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?

Reply With Quote
  #6  
Old December 7th, 2004, 02:13 PM
banker's Avatar
banker banker is offline
Charging Rhino Wizard
ASP Free Regular (2000 - 2499 posts)
 
Join Date: Dec 2004
Location: 127.0.0.1
Posts: 2,053 banker User rank is Sergeant Major (2000 - 5000 Reputation Level)banker User rank is Sergeant Major (2000 - 5000 Reputation Level)banker User rank is Sergeant Major (2000 - 5000 Reputation Level)banker User rank is Sergeant Major (2000 - 5000 Reputation Level)banker User rank is Sergeant Major (2000 - 5000 Reputation Level)banker User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 23 h 28 m 28 sec
Reputation Power: 37
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:
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)

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > SQL Insert into Multiple Tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT