Cycle through list run insert statement based on value from current row of list

I am trying to write  SQL Script that cycles through a column of values and performs an insert based on the value of the row. I have some written below.  I am struggling with how to cycle  through the list while running the insert statement for each siteid value.

create table #mytable
(isiteid int);

insert into #mytable values(20);
insert into #mytable values(291);
insert into #mytable values(347);
insert into #mytable values(469);
insert into #mytable values(473);
insert into #mytable values(635);
insert into #mytable values(722);
insert into #mytable values(729);
insert into #mytable values(754);
insert into #mytable values(760);
insert into #mytable values(967);
insert into #mytable values(1188);
insert into #mytable values(1390);
insert into #mytable values(1463);
insert into #mytable values(1489);

declare @isiteid int
declare @icnt int

select @icnt= count(*) from #mytable

--everything works fine until the line below
select @isiteid = top 1 isiteid from #mytable
 
while @icnt>0

insert into DMRepository
(iSiteId,vchDocName,iDocTypeId,vchSubject,vchMimeType,chUser,vchLogoPath,vchImgPath,
txtLitContent,iEmailType,iFaxType,iPrintType,tiRecordStatus,chUpdateBy,dtUpdateDate,iSurveyId,iAutoType,iTrackingEmail,DMRepositoryDocumentSourceId, OemLocked)
values
(@iSiteId,'Test',113128,’Test','text/html','fsjvera','','',
'Hello ',
1,1,0,1,'fsjvera',getdate(),0,1,1,2,0)

Delete top 1 from #mytable
Set @icnt= @icnt-1

end

Please let me know if any additional information is needed.
jverasqlAsked:
Who is Participating?
 
jverasqlAuthor Commented:
I figured out how to do what I wanted.  How do I close the question?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.