我有一个问题,我试图用不同的解决方案替换以下代码。目前我正在使用光标,但它运行缓慢。我的理解是迭代解决方案只能用游标或while循环完成,但我试图找到一种基于集合的方法并且没有想法。我希望我能在这里找到一些灵感。谢谢大家。
--used to find a unique list of Some_ID
@Id1, @Id2, @Id3
DECLARE SomeCursor CURSOR FOR
SELECT SOME_ID FROM SomeTable
WHERE ID1=@Id1 AND ID2=@Id2 and ID3=@Id3
OPEN SomeCursor
FETCH NEXT FROM SomeCursor INTO @SomeID
WHILE @@Fetch_Status = 0
BEGIN
Print @SomeID
--simply populates a single table with values pulled from
--other tables in the database based on the give parameters.
EXEC SP_PART1 @SomeID, @parameters...
print 'part 2 starting'
EXEC SP_PART2 @SomeID, @parameters...
FETCH NEXT FROM SomeCursor INTO @SomeID
print getdate()
END
CLOSE SomeCursor;
DEALLOCATE SomeCursor;