我有一个IDTable
包含一列的表,还有一个带有参数的ID
表值函数MyProcedure
。这个参数是我的专栏ID
。此函数返回一个表。我需要为 column 中的每个值调用此函数ID
。我有这样的代码:
Declare @ResultTable table(
ClientID nvarchar(50) null,
[Date] datetime null,
Item varchar(100) null
)
Declare @IDTable table(
id int
)
declare @counter as int
set @counter = isnull( (select max(id) from @IDTable),0)
while @counter<>0
begin
set @ID = (select id from @IDTable where id=@counter)
insert into @ResultTable
select ClientID
[Date],
Item
from MyProcedure (@ID)
delete from @IBTable where id=@counter
set @counter=isnull((select max(id) from @IBTable),0)
end
我需要删除 while 循环并制作基于集合的替代方案。我该怎么做?