给你一个例子:
我自己写的
declare rpt cursor for
SELECT distinct 商品编号,盘点日期
FROM V_商品盘点数量
declare @GNo varchar(50),
@PDate datetime
open rpt --打开光标
fetch next from rpt into @GNo,@PDate
while @@fetch_status =0
begin
insert into 盘点表_编号颜色尺码数量(店名,盘点日期,商品编号,颜色,尺码,数量)
select 店名,@PDate,商品编号,颜色,尺码,sum(数量) as 数量
from 盘点表_预核对商品总账数据
where 商品编号=@GNo and 日期<=@PDate group by 店名,商品编号,颜色,尺码
fetch next from rpt into @GNo,@PDate
end
close rpt
deallocate rpt