自己目前在用的,记录一下,方便以后进行使用
declare @myip nvarchar(100),@mypid int
DECLARE My_Cursor CURSOR --定义游标
FOR (SELECT
[P_Addr]
,[P_Id]
FROM [DbYiYang].[dbo].[Store_IP_Info]) --查出需要的集合放到游标中
OPEN My_Cursor; --打开游标
FETCH NEXT FROM My_Cursor into @myip ,@mypid ; --放置数据
WHILE @@FETCH_STATUS = 0
BEGIN
IF (select count(*) from [DbYiYang].[dbo].[Store_Machine] where m_ip like '%' + @myip + '%') > 0 or (select count(*) from [DbYiYang].[dbo].[Order_Add_IP_OneC] where IP_IP like '%' + @myip + '%') > 0
BEGIN
UPDATE [DbYiYang].[dbo].[Store_IP_Info]
SET [P_State] = '已用',
[P_StartTime] = getdate()
WHERE [P_Id] = @mypid;
END
ELSE
BEGIN
UPDATE [DbYiYang].[dbo].[Store_IP_Info]
SET [P_State] = '空闲',
[P_StartTime] = getdate()
WHERE [P_Id] = @mypid;
END
FETCH NEXT FROM My_Cursor into @myip ,@mypid; --读取下一行数据 放置数据
END
CLOSE My_Cursor; --关闭游标
DEALLOCATE My_Cursor; --释放游标
GO