主题:游标也出错
写了个触发器,但运行时更新操作时总出理
游标“My_curosr”已定义的错误,为什么呀,代码如下:
if exists(select * from SysObjects
where name='My_OverDraft' and Type='TR')
Drop Trigger My_OverDraft
go
create Trigger My_OverDraft on Account
for update,insert
as
declare @b float,@bid varchar(10),@cid Varchar(20)
declare My_Cursor cursor for
select Account.Balance,Account.bankID,Account.CardID from Account,inserted
where Account.bankID=inserted.bankID and Account.CardID=inserted.CardID
open My_cursor
fetch My_cursor into @b,@bid,@cid
while(@@fetch_status=0)
begin
if @b<10
begin
insert into [Check](BankID,CardID,overDraft,AllDays)
values(@bid,@cid,10-@b,60)
update Account
Set balance=10
where BankID=@bid and CardID=@Cid
update card set overDraft=0
where BankID=@Bid and CardID=@CId
end;--end if
fetch My_cursor into @b,@bid,@cid
end;
close My_Cursor
deallocate My_Cursor
游标“My_curosr”已定义的错误,为什么呀,代码如下:
if exists(select * from SysObjects
where name='My_OverDraft' and Type='TR')
Drop Trigger My_OverDraft
go
create Trigger My_OverDraft on Account
for update,insert
as
declare @b float,@bid varchar(10),@cid Varchar(20)
declare My_Cursor cursor for
select Account.Balance,Account.bankID,Account.CardID from Account,inserted
where Account.bankID=inserted.bankID and Account.CardID=inserted.CardID
open My_cursor
fetch My_cursor into @b,@bid,@cid
while(@@fetch_status=0)
begin
if @b<10
begin
insert into [Check](BankID,CardID,overDraft,AllDays)
values(@bid,@cid,10-@b,60)
update Account
Set balance=10
where BankID=@bid and CardID=@Cid
update card set overDraft=0
where BankID=@Bid and CardID=@CId
end;--end if
fetch My_cursor into @b,@bid,@cid
end;
close My_Cursor
deallocate My_Cursor