kaveer
9/19/2017 - 4:44 AM

Loop in sql

insert into #temp(AdvertId, Keyword)
select intAd_id, chrKeywords 
from netdirectories..advert
where intAd_id in (1198, 32385, 785529, 785340, 785221, 662905, 662906, 1613, 357402, 357394, 779973, 1612)

select * from #temp

While ((Select Count(*) From #temp) <> 0 )
    Begin
	   declare 
		  @id int,
		  @keyword varchar(1000)
	   select top 1
		  @id = advertId,
		  @keyword = keyword
	   from #temp

	  update advert
	  set chrKeywords = @keyword
	  where intAd_id = @id

	  delete from #temp
	  where AdvertId = @id

    End