-- 创建临时表
IF OBJECT_ID('tempdb.dbo.#temprecord','U') IS NOT NULL DROP TABLE dbo.#temprecord;
GO
SELECT Id
INTO dbo.#temprecord
FROM dbo.t_BaiduIncludedRecord
DECLARE
@Id Int
WHILE EXISTS(SELECT Id FROM dbo.#temprecord)
BEGIN
-- 也可以使用top 1
SET ROWCOUNT 1
--逻辑处理
SELECT @Id=Id FROM dbo.#temprecord;
update t_BaiduIncludedRecord set Remark=(Select round(rand()*2+1,0)) where Status=0 AND Id = @Id
SET ROWCOUNT 0
-- 删除临时表
DELETE FROM dbo.#temprecord WHERE Id=@Id;
END
SELECT * FROM dbo.t_BaiduIncludedRecord