Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2002
    Location
    Land of OZ
    Posts
    173

    Unanswered: Insert Into Statements

    Hi guys,

    This is what I need to do.

    I have two tables (Company and Contact). Both have a primary key which is an autonumber. These tables are linked.

    I need to perform an Insert Into on table Company, then an Insert Into on table Contact and setting the FK in Contact to equal the PK of the Company table.

    Can I do this with one SQL string. Or will I have to bookmark the new record in the Company table and then pick up the PK from the Company table to Insert Into as part of the Contact table.

    Cheers
    Mona
    Mona
    ________________________________
    Life is too short to be sane or sensible. Weird people rule and normal people suck

  2. #2
    Join Date
    Jun 2002
    Location
    Vienna, VA
    Posts
    53
    You will need two sql statements, or two append queries will work as well.

    You'll need to insert the company first, then get the new id, and use that to insert the contact.


    Leah

  3. #3
    Join Date
    Sep 2002
    Location
    Land of OZ
    Posts
    173
    Originally posted by justmeleah
    You will need two sql statements, or two append queries will work as well.

    You'll need to insert the company first, then get the new id, and use that to insert the contact.


    Leah
    Thank you for that, but my concern is picking up the new id at the end of the insert.

    That is the current solution that I am using, however this is a web application and there are 5000 users ...anyone creating at any time. So I was wondering if I could achieve this with one SQL statement

    Cheers
    Mona
    Mona
    ________________________________
    Life is too short to be sane or sensible. Weird people rule and normal people suck

  4. #4
    Join Date
    Mar 2003
    Posts
    8

    forms and subforms

    You can use subforms related to main form (company) for inserting directly the data.
    The problem with SQL is that you can not append two tables with single Insert line, so you will need two of them. That's why you should look for other solutions.

    -----------------------------------------------------------------------------------

  5. #5
    Join Date
    Sep 2002
    Location
    Land of OZ
    Posts
    173

    Re: forms and subforms

    Originally posted by luftari
    You can use subforms related to main form (company) for inserting directly the data.
    The problem with SQL is that you can not append two tables with single Insert line, so you will need two of them. That's why you should look for other solutions.

    -----------------------------------------------------------------------------------
    Again, a subform is not a solution here as this is an asp applications. Thnaks anyway for your help.
    Mona
    ________________________________
    Life is too short to be sane or sensible. Weird people rule and normal people suck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •