declare @intRoomID int
declare RoomList_cursor cursor for
select fdRoomID From tb_RoomInfo
open RoomList_cursor
fetch next from RoomList_cursor into @intRoomID
while @@fetch_status=0
begin
print @intRoomID
FETCH NEXT FROM RoomList_cursor INTO @intRoomID --缺少一句,指针没有向下走,进入死循环了
end
close RoomList_cursor
deallocate RoomList_cursor
delete from tb_Online Where Datediff(n,fdLastActive,getDate())>20;
GO
declare @intRoomID int
declare RoomList_cursor cursor for
select fdRoomID From tb_RoomInfo
open RoomList_cursor
fetch next from RoomList_cursor into @intRoomID
while @@fetch_status=0
begin
print @intRoomID
end
close RoomList_cursor
deallocate RoomList_cursor
--这样试一下!
--具体步骤:
企业管理器
--管理
--SQL Server代理
--右键作业
--新建作业
--"常规"项中输入作业名称
--"步骤"项
--新建
--"步骤名"中输入步骤名
--"类型"中选择"Transact-SQL 脚本(TSQL)"
--"数据库"选择执行命令的数据库
--"命令"中输入要执行的语句:
Declare @i Int
Set @i=1
While @i<=10
Begin
Exec ('
Delete Table'+Rtrim(@I) +'
Where DateDiff(Hour,时间字段,Getdate())=1')
Set @i=@i+1
End