Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2010
    Posts
    13

    Unanswered: Insert into one table based on one condition and insert into another based on another

    Hey all,

    So I started out this query fine. But towards the end where I begin speaking english in the query is because I don't know how to do it. All I know is it needs to be one whole query but based on one condition, it is inserted into one table and based on another condition it's inserted into another table. This is in Microsoft Access.

    Code:
        SELECT contacts.id, contacts.names_1, contacts.names_2, contacts.addresses INTO PrepareForDuplicateCheck
        FROM contacts, possibles
        WHERE (INSTR(CONTACTS.NAMES_1, possibles.fullname) > 0)
        Or
        (INSTR(CONTACTS.NAMES_2, possibles.fullname) > 0) 
        and
        (
        CONTACTS.us_states_and_canada = "FL"
        or
         CONTACTS.us_states_and_canada = "NY"
        ) 
        and IIF(possibles.middle_initial IS NOT NULL)
        BUT if the first, last, and middle initial cannot be found together in Contacts using the conditionh specified in the INSTR function then
         INSERT INTO Extras
       (INSTR(CONTACTS.NAMES_2, possibles.first_and_last_name) > 0) 
    ;
    Last edited by johnmerlino; 10-22-10 at 00:05.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    It would be easy in SQL on a server, unfortunately an Access Query does not offer the same possibilities as SQL Stored Procedures do.

    You'll probably have to use some VBA code in addition to SQL to achieve what you're trying to do.
    Have a nice day!

  3. #3
    Join Date
    Oct 2010
    Posts
    51
    What are the different conditions? Are they based on form data? Or are you trying to migrate data form one table into another other tables?

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Just write two queries, one inserting into one table and one into another. Simples.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Tags for this Thread

Posting Permissions

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