我新建了一个存储过程,内容如下:
CREATE PROCEDURE prcCheckSummary AS
truncate table tbsumtemp
GO
declare @strStuId nvarchar(30)
declare cur_Id  cursor  local for select idcard  from  tbstudent
open cur_Id
fetch next from cur_Id into @strStuId
while @@fetch_status=0
begin
update tbsumtemp set  
mpayment=isnull((select sum(mpayment) from tbpayment p where p.idcard=@strStuId),0),
mgrant=isnull((select sum(mgrant) from tbpayment p where p.idcard=@strStuId),0),
mscholarships=isnull((select sum(mscholarships) from tbpayment p where p.idcard=@strStuId),0),
mrefund=isnull((select sum(mrefund) from tbpayment p where p.idcard=@strStuId),0)
where tbsummary.idcard=@strStuId

update tbsumtemp set  
tuition=isnull((select sum(tuition) from tbcharge c where c.idcard=@strStuId),0),
dormitoryfee=isnull((select sum(dormitoryfee) from tbcharge c where c.idcard=@strStuId),0),
otherfee=isnull((select sum(otherfee) from tbcharge c where c.idcard=@strStuId),0),
where tbsummary.idcard=@strStuId
fetch next from cur_Id into @strStuId
end
close cur_Id
deallocate cur_Id
         go点确定以后,再打开,就只剩下
CREATE PROCEDURE prcCheckSummary AS
truncate table tbsumtemp
GO
怎么回事啊?焦急中

解决方案 »

  1.   

    CREATE PROCEDURE prcCheckSummary AS
    truncate table tbsumtemp
    GO------------------------
    这一句问题多多啊,不知道你想做什么,首先把GO去掉,再一个就是为什么一开始就用truncate table tbsumtemp,这个可是把表里的数据全删掉了,只留下表结构。你把
    truncate table tbsumtemp
    GO
    这两个全删掉,再试试吧~
      

  2.   

    改成这样~CREATE PROCEDURE prcCheckSummary 
    AS
    declare @strStuId nvarchar(30)
    declare cur_Id  cursor  local for select idcard  from  tbstudent
    open cur_Id
    fetch next from cur_Id into @strStuId
    while @@fetch_status=0
    begin
    update tbsumtemp set  
    mpayment=isnull((select sum(mpayment) from tbpayment p where p.idcard=@strStuId),0),
    mgrant=isnull((select sum(mgrant) from tbpayment p where p.idcard=@strStuId),0),
    mscholarships=isnull((select sum(mscholarships) from tbpayment p where p.idcard=@strStuId),0),
    mrefund=isnull((select sum(mrefund) from tbpayment p where p.idcard=@strStuId),0)
    where tbsummary.idcard=@strStuId

    update tbsumtemp set  
    tuition=isnull((select sum(tuition) from tbcharge c where c.idcard=@strStuId),0),
    dormitoryfee=isnull((select sum(dormitoryfee) from tbcharge c where c.idcard=@strStuId),0),
    otherfee=isnull((select sum(otherfee) from tbcharge c where c.idcard=@strStuId),0),
    where tbsummary.idcard=@strStuId
    fetch next from cur_Id into @strStuId
    end
    close cur_Id
    deallocate cur_Id
             go点确定以后,再打开,就只剩下
    CREATE PROCEDURE prcCheckSummary AS
    truncate table tbsumtemp
    GO
    怎么回事啊?焦急中
      

  3.   

    不好意思,一开始是这样的,漏了一句话:
    CREATE PROCEDURE prcCheckSummary AS
    truncate table tbsumtemp
    go
    insert into tbsumtemp(idcard,classno,majorno) select idcard,classno,majorno from tbstudent
    GO我把go去掉就对了,谢谢拉