Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7722553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:12:28+00:00 2026-06-01T04:12:28+00:00

I am trying to insert data from one table that was imported from an

  • 0

I am trying to insert data from one table that was imported from an Excel file into another table with the same exact columns. When I go to insert all the data

    INSERT INTO [NQL_RawData].[dbo].[WM_MFGPNs]
    ([Manufacturer],[MPNWP],[MFGPN],[Cage],[Url],[DataSheetUrl],[Description],[Status],[NRND],[RoHS],[PbFree],[LOT],[LeadTime],[AddedOn],[AddedBy])

    SELECT [Manufacturer],dbo.BuildPNWP([MFGPN],0),[MFGPN],[Cage],[Url],[DataSheetUrl],[Description],[Status],[NRND],[RoHS],[PbFree],[LOT],[LeadTime],[AddedOn],[AddedBy]

    FROM [NQL_RawData].[dbo].[wm_BulkImport] WHERE Manufacturer = 'MFG NAME'        

it comes up with this error message

Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint ‘PK_MFGPNs_1’. Cannot insert duplicate key in object ‘dbo.WM_MFGPNs’.
The statement has been terminated.

So I changed the query to include WHERE NOT EXISTS

    INSERT INTO [NQL_RawData].[dbo].[WM_MFGPNs]
    ([Manufacturer],[MPNWP],[MFGPN],[Cage],[Url],[DataSheetUrl],[Description],[Status],[NRND],[RoHS],[PbFree],[LOT],[LeadTime],[AddedOn],[AddedBy])

    SELECT [Manufacturer],dbo.BuildPNWP([MFGPN],0),[MFGPN],[Cage],[Url],[DataSheetUrl],[Description],[Status],[NRND],[RoHS],[PbFree],[LOT],[LeadTime],[AddedOn],[AddedBy]

    FROM [NQL_RawData].[dbo].[wm_BulkImport] 

    WHERE NOT EXISTS( 
    SELECT [MFGPN] 
    FROM [NQL_RawData].[dbo].[WM_MFGPNs]
    WHERE Manufacturer = 'MFG NAME'     
    )

But I still receive the same error message. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:12:30+00:00Added an answer on June 1, 2026 at 4:12 am

    At a wild guess, the PK of WM_MFGPNs isn’t Manufacturer, but another column, such as MFGPN.
    Assuming this to be the case, your insert becomes

    INSERT INTO [NQL_RawData].[dbo].[WM_MFGPNs]
        ([Manufacturer],[MPNWP],[MFGPN],[Cage],[Url],[DataSheetUrl],[Description],[Status],[NRND],[RoHS],[PbFree],[LOT],[LeadTime],[AddedOn],[AddedBy])
    
        SELECT [Manufacturer],dbo.BuildPNWP([MFGPN],0),[MFGPN],[Cage],[Url],[DataSheetUrl],[Description],[Status],[NRND],[RoHS],[PbFree],[LOT],[LeadTime],[AddedOn],[AddedBy]
    
        FROM [NQL_RawData].[dbo].[wm_BulkImport] blkimp
    
        WHERE
           Manufacturer = 'MFG NAME' -- Your original import filter
        AND NOT EXISTS -- Prevent duplicate insertions
        ( 
        SELECT [MFGPN] 
        FROM [NQL_RawData].[dbo].[WM_MFGPNs] mfgpn
        WHERE blkimp.MFGPN = mfgpn.MFGPN
        )
    

    Edit : OK, Your table has a Composite Primary Key (i.e. the combination of 2 or more fields comprises a unique key).

    INSERT INTO [NQL_RawData].[dbo].[WM_MFGPNs]
        ([Manufacturer],[MPNWP],[MFGPN],[Cage],[Url],[DataSheetUrl],[Description],[Status],[NRND],[RoHS],[PbFree],[LOT],[LeadTime],[AddedOn],[AddedBy])
    
        SELECT [Manufacturer],dbo.BuildPNWP([MFGPN],0),[MFGPN],[Cage],[Url],[DataSheetUrl],[Description],[Status],[NRND],[RoHS],[PbFree],[LOT],[LeadTime],[AddedOn],[AddedBy]
    
        FROM [NQL_RawData].[dbo].[wm_BulkImport] blkimp
    
        WHERE
           Manufacturer = 'MFG NAME' -- Your original import filter
        AND NOT EXISTS -- Prevent duplicate insertions
        ( 
        SELECT [MFGPN] 
        FROM [NQL_RawData].[dbo].[WM_MFGPNs] mfgpn
        WHERE blkimp.MFGPN = mfgpn.MFGPN
              AND blkimp.Manufacturer = mfgpn.Manufacturer
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert data from one of my existing table into another
Im trying to copy over data from one table to another in the same
I am trying to insert some data into one table and after that is
I am trying to select data from two tables and insert it into another
In SQL server, I am trying to insert values from one table to another
I'm trying to insert data to a table from another table and the tables
In the SQL Server, I am trying to insert values from one table to
I need to copy some data from one table to another but I need
I'm trying to aggregate some customer order data into one table for analysis. The
Language: OO PHP 5+ DB: MySQL I am trying to insert data from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.