ALTER trigger latest_time
on bill for update
as
if update(stateID)
begin
declare daysell cursor for --创建一个名为daysell的只读游标
select billID from inserted
for read only
declare @billID bigint --声明变量
open daysell --打开游标
fetch daysell --从游标取一行数据
into @billID
while(@@fetch_status=0) --是否处理完所有行记录
begin
update goods
set latest= getdate()
where billID=@billID
fetch daysell
into @billID
end
end
on bill for update
as
if update(stateID)
begin
declare daysell cursor for --创建一个名为daysell的只读游标
select billID from inserted
for read only
declare @billID bigint --声明变量
open daysell --打开游标
fetch daysell --从游标取一行数据
into @billID
while(@@fetch_status=0) --是否处理完所有行记录
begin
update goods
set latest= getdate()
where billID=@billID
fetch daysell
into @billID
end
end
语句已终止。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 名为 'daysell' 的游标已存在。
语句已终止。