游标问题,输出为表,在线等急
查询统计,查询表Company表中的记录在Equip表中的记录数(1:N的关系)
查询出来的结果怎么输出到一张表中呢?
declare @ID int
declare @ManagerID int
declare tn cursor local for
select ID,ManagerID from Company order by ManagerID
open tn
fetch next from tn into @ID,@ManagerID
while @@fetch_status = 0
begin
select count(equipID) from Equip where GKID = @ID
fetch next from tn into @ID,@ManagerID
end
close tn
deallocate tn