Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2004
    Posts
    164

    Unanswered: Adding Query Results To A Tbale

    hello everybody,

    I have a small problem and was hipeing someone could help. Want to run a query, where I sellect results from two tables. Once this is done I want to takes those results and update a table that is already created with those results. How would I do this? Thw eonly way I know how to do this is by writing this:

    select CompanyName, ContactName, Address, City, Region, ProductName, UnitPrice INTO TABLE2
    From Suppliers, Products

    But the problem with this is that I can only input the query results into a new table that I would name above. I can't insert it into a table that has already been created.

    This is the erroe that I receive:
    There is already an object named 'TABLE2' in the database.

    Please Help!

    thanks

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    INSERT INTO TABLE2 (
    CompanyName
    , ContactName
    , Address
    , City
    , Region
    , ProductName
    , UnitPrice)
    SELECT
    CompanyName
    , ContactName
    , Address
    , City
    , Region
    , ProductName
    , UnitPrice
    From Suppliers, Products


    I'd also say you're missing a JOIN
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Jan 2004
    Posts
    164
    So say that information changes on the 2 tables that I am querying, when I run this insert code with the query, it will reinsert all the records into table2, which will basically be updating it. Am i getting this right? Thats what I am trying to do. I could also turn that into a job so that it could run automatically right?

    thanks

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    Inserting will add records to the table unless you have constraints that prevent duplicate records/keys. Updating modifies the original field(s) of the record you are working with. Are you new to database design ?

  5. #5
    Join Date
    Feb 2002
    Posts
    2,232
    Can you elaborate what you are trying to do ?

  6. #6
    Join Date
    Jan 2004
    Posts
    164
    Originally posted by rnealejr
    Inserting will add records to the table unless you have constraints that prevent duplicate records/keys. Updating modifies the original field(s) of the record you are working with. Are you new to database design ?
    Actually yes, I am new to this. Thats probably why I sound redundante. So I need as much help as possibel

    thanks

  7. #7
    Join Date
    Jan 2004
    Posts
    164
    Originally posted by rnealejr
    Can you elaborate what you are trying to do ?
    Okay, here it goes. I created a table called "table1". This table has all the columns named already. I want to hold records from a a query that I run on two other tables and then place the results in table2. The colums that I query are named the same as the columns I created in table2. I just want all those records to show up in table2.

  8. #8
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Aren't you planning on using the code I posted?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  9. #9
    Join Date
    Jan 2004
    Posts
    164
    Originally posted by Brett Kaiser
    Aren't you planning on using the code I posted?
    ACTUALLY i USED IT AND IT WORKED WELL. i WAS JUST WONDERING IF THERE WERE OTHER WAYS OF DOING IT.
    THANKS FOR YOUR HELP. i AM PRETTY NEW AT THIS.

Posting Permissions

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