请帮忙看一存储过程问题
ALTER PROCEDURE jhtjb_bm
@begindate datetime,
@enddate datetime,
@bmbh char(10)
AS
declare @t TABLE (spbm varchar(50) null,
spmc varchar(100) null,
jhsl decimal(18,2) null,
jese decimal(18,2) null,
jhzj decimal(18,4) null)
declare @spbm varchar(50),
@spmc varchar(100),
@jhsl decimal(18,2),
@jese decimal(18,2),
@jhzj decimal(18,2)
DECLARE @pro_cursor_spbm CURSOR
SET @pro_cursor_spbm = CURSOR FOR
SELECT DISTINCT left(b.spbm,2) as spbm,c.spmc
FROM jhd a,jhsp b,commodify c
where a.jhbh=b.jhbh AND left(b.spbm,2)=c.spbm and c.dept_id=@bmbh and
datediff(dd,a.jhrq,@begindate)<=0 and datediff(dd,a.jhrq,@enddate)>=0 and b.zt<>'9'
OPEN @pro_cursor_spbm
FETCH next FROM @pro_cursor_spbm INTO @spbm,@spmc
WHILE (@@FETCH_STATUS = 0)
BEGIN
declare @Nowbmbh char(10)
select @Nowbmbh=min(a.bmbh),@jhsl=isnull(sum(b.jhsl - isnull(b.thsl,0)),0),@jese = isnull(sum(b.jese),0),@jhzj = isnull(sum(b.jhzj),0)
from jhd a,jhsp b,commodify c
where (a.jhbh=b.jhbh) and c.spbm=@spbm AND a.bmbh=@bmbh and
datediff(dd,a.jhrq,@begindate)<=0 and datediff(dd,a.jhrq,@enddate)>=0 and b.zt<>'9'
group by left(b.spbm,2),c.spmc
if @nowbmbh = @bmbh
begin
insert into @t SELECT @spbm,@spmc,@jhsl,@jese,@jhzj
end
FETCH next FROM @pro_cursor_spbm INTO @spbm,@spmc
END
--insert into @t SELECT @spbm,@spmc,@jhsl,@jese,@jhzj
CLOSE @pro_cursor_spbm
DEALLOCATE @pro_cursor_spbm
select * from @t
上面的可以运行,根据条件能查询的正确的数据记录N条;但显示的数据总是N条记录中最后一条的数据? 麻烦大家帮忙看看,谢谢