谢谢大家帮我看看什么问题
我写了一个存储过程,功能是把一段日期内的所有的司机的收入算出来,包括他做为主班司机和替班司机的.然后插入到一个表中去,就是这么简单.我建了一些视图,我保证那些视图没有问题,然后从那些视图里面根据条件把所有属于主班的钱和属于替班的钱分别放到表中的各个字段,可是我现在检索出来的数据全是零,我的视图没有问题,因为我用它们同样的做过数据窗口都检索出来了,所以大家帮我看看是不是哪个地方写的不对.谢谢.我水平很差,还有一些比如是否执行成功的判断条件也没有写,大家一并帮我看看吧,谢谢了.(替班的语句我没写和主的一样,我想主的问题找出来替班的问题一样就出来了)
create procedure acc_sijishouru_proc (@ld_beg datetime,@ld_end datetime) as
declare @ls_hao char(12),
@ls_name varchar(8),
@ln_mainmoney decimal(8,2),
@ln_vicemoney decimal(8,2),
@ln_mainshoumoney decimal(8,2),/*???????????????????????????*/
@ln_mainfumoney decimal(8,2),
@ln_viceshoumoney decimal(8,2),
@ln_vicefumoney decimal(8,2),
@ln_shoumoney decimal(8,2),
@ln_fumoney decimal(8,2)
declare sijiname_cur cursor for
SELECT Trucker.Trucker_No
FROM Trucker
ORDER BY Trucker.Trucker_No ASC ;
open sijiname_cur;
fetch sijiname_cur
into @ls_name
while @@fetch_status =0
begin
SELECT @ln_shoumoney =sum(acc_miansijishoumoney_view.fumoney )
FROM acc_miansijishoumoney_view
WHERE ( acc_miansijishoumoney_view.c_driver_main = @ls_name ) AND
( acc_miansijishoumoney_view.D_paicheriqi >= @ld_beg ) AND
( acc_miansijishoumoney_view.D_paicheriqi <= @ld_end ) ;
if @ln_shoumoney is null
begin
set @ln_shoumoney=0
end
SELECT @ln_fumoney = sum(acc_miansijifumoney_view.fumoney )
FROM acc_miansijifumoney_view
WHERE ( acc_miansijifumoney_view.c_driver_main = @ls_name ) AND
( acc_miansijifumoney_view.D_paicheriqi >= @ld_beg ) AND
( acc_miansijifumoney_view.D_paicheriqi <= @ld_end ) ;
if @ln_fumoney is null
begin
set @ln_fumoney=0
end
select @ln_mainmoney=@ln_mainmoney - @ln_fumoney
if @ln_mainmoney is null
begin
set @ln_mainmoney=0
end
select @ls_hao=convert(char(6),@ld_beg,112)+convert(char(6),@ld_end,112)
INSERT INTO acc_sijishouru_main_tab
( c_riqihao,
c_name,
n_main_lirun,
n_vice_lirun,
n_shouru,
vc_remark )
VALUES ( @ls_hao,
@ls_name,
@ln_mainmoney,
@ln_vicemoney,
null,
null ) ;
if @@error<0
begin
raiserror('??????',16,10)
return
end
fetch sijiname_cur
into @ls_name
end;
close sijiname_cur;
deallocate sijiname_cur;