Inserting table data in to another table

Just going crazy on what's wrong here.

all I am trying to do is : "Take two columns from one table and insert in to other table"

enter image description here

The query that I use is this:

insert into Component_Capacitor values (Component_Capacitor.itemNo, Component_Capacitor.itemDescription)
  select [Item No#], [Item Description] from dbo.Sheet1$ where 
  [Item Description] LIKE 'CAP %' ;

The error is this:

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Component_Capacitor.itemNo" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "Component_Capacitor.itemDescription" could not be bound.

I checked the syntax, table-name and everything seems to be fine.

The column types are also similar (nvarchar(255),null)

Any ideas what am I doing wrong ?

Upvotes: 0

Views: 82

Answers (4)

Aditya
Aditya

Reputation: 2311

Replace column names & table names properly. This should work.

INSERT INTO DBO.COMPONENT_CAPACITOR (ITEMNO, ITEMDESCRIPTION)
SELECT A.ITEMNO, A. ITEMDESCRIPTION FROM SHEET A
WHERE ITEMDESCRIPTION LIKE 'CAP%' 

Upvotes: 2

user3044294
user3044294

Reputation: 205

use ItemNo for the Item No and same things in Item Description simple remove the White space. and remove values name in code

Upvotes: 0

Marc
Marc

Reputation: 11633

I don't use SQL Server, but I think you need to remove the word "values" from your statement.

insert into Component_Capacitor (Component_Capacitor.itemNo, Component_Capacitor.itemDescription)
  select [Item No#], [Item Description] from dbo.Sheet1$ where 
  [Item Description] LIKE 'CAP %' ;

Upvotes: 3

Raj
Raj

Reputation: 10853

insert into Component_Capacitor 
(Component_Capacitor.itemNo, Component_Capacitor.itemDescription)
  select [Item No#], [Item Description] from dbo.Sheet1$ where 
  [Item Description] LIKE 'CAP %' ;

Upvotes: 2

Related Questions