declare @sectionId int = 0 -- ID sluzby, na ktere chceme menit proces declare @targetProcessId int = 0 -- ID procesu na ktery chceme sluzbu zmenit update tHdSection set TicketTypeId=@targetProcessId where iHdSectionId = @sectionId; create table #ticketsToUpdate ( id int primary key, processed int) insert into #ticketsToUpdate select iHdTicketId,0 from tHdTicket where liHdTicketHdSectionId=@sectionId while(exists(select 1 from #ticketsToUpdate where processed=0)) begin declare @id int; select @id=id from #ticketsToUpdate where processed=0 exec spUpdateSlaPausedHours @id update #ticketsToUpdate set processed=1 where id = @id end drop table #ticketsToUpdate