Insert Select Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Py

    Insert Select Help


    I need a query that looks at one table and appends another if new
    customer data is added. I think I need an Insert, Select statement using
    the NOT IN clause.

    I need to compare Division, CustomerNumber of the two tables.

    Help, Example Appreciated. Thanks
    Frank


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Simon Hayes

    #2
    Re: Insert Select Help


    "Frank Py" <fpy@proactnet. com> wrote in message
    news:3fd88fd6$0 $199$75868355@n ews.frii.net...[color=blue]
    >
    > I need a query that looks at one table and appends another if new
    > customer data is added. I think I need an Insert, Select statement using
    > the NOT IN clause.
    >
    > I need to compare Division, CustomerNumber of the two tables.
    >
    > Help, Example Appreciated. Thanks
    > Frank
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]

    You should post the DDL for your tables to get a more precise response, but
    I guess you need something like this:

    insert into dbo.TargetTable
    (col1, col2, ...)
    select col1, col2, ...
    from dbo.SourceTable s
    where not exists (
    select *
    from dbo.TargetTable t
    where t.Division = s.Division and
    t.CustomerNumbe r = s.CustomerNumbe r
    )

    If that guess isn't helpful, please post the DDL for both tables, including
    keys.

    Simon


    Comment

    • Frank Py

      #3
      Re: Insert Select Help


      Yes, that's basically it! I used MS Access to help me with some of the
      syntax (dont' tell anyone). This is what I ended up with and it seems to
      test good:

      INSERT INTO TmemberPassword s ( Division, CustomerNumber )
      SELECT AR1_CustomerMas ter.Division, AR1_CustomerMas ter.CustomerNum ber
      FROM AR1_CustomerMas ter
      WHERE (((AR1_Customer Master.Division ) Not In (Select
      [TmemberPassword s].[Division] From [TmemberPassword s])) AND
      ((AR1_CustomerM aster.CustomerN umber) Not In (Select
      [TmemberPassword s].[CustomerNumber] From [TmemberPassword s])));

      Thanks,
      Frank


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...