脑子混乱了 要好好整理下思路

declare
@i int,
@num int,
@companyid varchar(20)
set @i=1
set @num=(select count(distinct companyid) from finance.dbo.Bill where companyid in (select companyid from finance.dbo.Company where XiangmuUserid='250'))
while @i<=@num
begin
select  top 1  @companyid=companyid  from finance.dbo.Bill where companyid in (select companyid from finance.dbo.Company where XiangmuUserid='250')
and companyid not in
(select top (@i-1)  companyid  from finance.dbo.Bill where companyid in (select companyid from finance.dbo.Company where XiangmuUserid='250')
 group by companyid)
 group by companyid
 print @companyid
set @i=@i+1
end

posted @ 2011-07-18 17:25  十年如一  阅读(257)  评论(0编辑  收藏  举报