I am trying to insert new data into an table using existing data from the same table as reference.
For example:
Insert into dbo.table1
(column1,column2,column3,column5,column5,id)
select column1,column2,column3,column5,column5,id = '' --the id is being pulled from xlsx
from dbo.table1
where column1 = '12345'
and id = 'xyz' --copying from this id to the id value above`
So i can run this 1 at a time and it works just fine but I need to be able to do it 141 times w/o having to copy and paste 141 times. I am hoping that I can use a single script to insert 141 records using the same reference id.
Insert into dbo.table1
(column1,column2,column3,column5,column5,id)
select column1,column2,column3,column5,column5,id = 'abc'
from dbo.table1
where column1 = '12345'
and id = 'xyz' --copying from this id to the id value above
--(1 row affected)--
Insert into dbo.table1
(column1,column2,column3,column5,column5,id)
select column1,column2,column3,column5,column5,id = 'def'
from dbo.table1
where column1 = '12345'
and id = 'xyz' --copying from this id to the id value above
--(1 row affected)--
Insert into dbo.table1
(column1,column2,column3,column5,column5,id)
select column1,column2,column3,column5,column5,id = 'ghi'
from dbo.table1
where column1 = '12345'
and id = 'xyz' --copying from this id to the id value above
--(1 row affected)--
New contributor
Gandalf the Grey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.