I try to insert data from one table into another table
table 1 (from where I select data )
update
divid divname
--------------
1 abc
2 def
4 xyz
5 fgh
6 ekg
8 sdf
table2 (table from where I insert data into)
divdw_id divid
update: i want data like this
divdw_id divid
001 1
002 2
003 4
004 5
005 6
006 8
I try this this query for inserting data but this shows an error
insert into table2
values (001, Divid)
select DivId
from Oper_Db.dbo.table1
but this shows an error
Invalid column name 'Divid'.
So how do I resolve this error?
UPDATE:
when i run only select statement query
insert into DivisionMap (divBI_Id, DiviOp_id)
select RIGHT('000'+CAST(eindex as VARCHAR(3)),3),eindex from mydatabase.dbo.employee
then this shows like this
(No column name) eindex
000 0
022 22
024 24
025 25
027 27
028 28
where as i want like this
(No column name) eindex
000 0
001 22
002 24
003 25
004 27
005 28
Invalid column name 'Divid'.clearly states the problem: Your column name isdividbut your'e selectingDivIdin your query which is difference.