0

Running this SQL statement:

INSERT INTO Describe (Product_ID, Spec_Category, Spec_Type, Spec_Desc)
    SELECT DISTINCT 
        Products.Product_ID,
        Spec_Category,
        Spec_Type,
        Spec_Desc
    FROM 
        UnknownTable1
    INNER JOIN 
        Products ON Products.Product_ID = Describe.Product_ID

I get this error:

Msg 4104, Level 16, State 1, Line 30
The multi-part identifier "Describe.Product_ID" could not be bound.

This has issue because of foreign key...anyone can explain?

Judge15
  • 9
  • 3
  • 1
    Come on. `UnknownTable1` and `Describe` - how should that work? – juergen d May 12 '18 at 04:51
  • Possible duplicate of [The multi-part identifier could not be bound](https://stackoverflow.com/questions/14082520/the-multi-part-identifier-could-not-be-bound) – Venki WAR May 12 '18 at 04:51
  • Your question makes no sense. First, the error is pretty obvious. Second, why are you using the table being inserted into in the `select`. Sample data and desired results would help. – Gordon Linoff May 12 '18 at 11:35
  • Product_id was supposed to be product_url but it's giving me error for pk violation...can't insert duplicates – Judge15 May 12 '18 at 16:46

1 Answers1

0

You have not included "Describe" table in your select query. Your query should be like this:

INSERT INTO Describe (Product_ID, Spec_Category, Spec_Type, Spec_Desc)
SELECT DISTINCT 
        Products.Product_ID
        ,Spec_Category
        ,Spec_Type
        ,Spec_Desc
FROM UnknownTable1
    INNER JOIN 
        Products
    ON
    Products.Product_ID = UnknownTable1.Product_ID

If you want to added this Products.Product_ID = Describe.Product_ID condition then you need to include Describe in your select query

Rajesh Pandya
  • 1,540
  • 4
  • 18
  • 31
  • Msg 207, Level 16, State 1, Line 73 Invalid column name 'Product_ID – Judge15 May 12 '18 at 04:58
  • Is UnknownTable1 contain the column "Product_Id"? What is the structure of your table UnknownTable1 and Products. – Rajesh Pandya May 12 '18 at 05:00
  • UnknownTable1 doesn't constaint product_id. I added it myself to differentiate products by adding Product_ID as PK. Unknowntable1 only has name, url, price. then im using product_id as FK & PK in describe. im not allowed to modify unknowntable1. – Judge15 May 12 '18 at 05:03
  • 1
    @Judge15 If UnknownTable1 doesn't have product_id then how you join two table UnknownTable1 and Products if both table have different column. Please edit your question and some sample out put data and table structure of both table – Rajesh Pandya May 12 '18 at 05:08
  • I modified my model.Now it contains product_url from unknowntable1 as PK. how would i go about inserting data...the columns are same as i posted before the only difference is product_id is now product_url....there are 549 unique urls but the way specs are listed under spec_category are like processor, connectivity..etc. each spec having own cell with same url,...when i execute the statement you posted i get error "Violation of PRIMARY KEY constraint 'PK_Describe_Product_URL'. Cannot insert duplicate key in object 'dbo.Describe'. – Judge15 May 12 '18 at 07:55