declare @id int
declare #tb cursor for select Id from a where Flag=1
open #tb
fetch next from #tb into @id
while @@fetch_status =0
begin
select Name from a where Id=@id
fetch next from #tb into @id
end
close #tb
deallocate #tb
declare @id int
declare #tb cursor for select Id from a where Flag=1
open #tb
fetch next from #tb into @id
while @@fetch_status =0
begin
select Name from a where Id=@id
fetch next from #tb into @id
end
close #tb
deallocate #tb