//存储过程
USE [database]
GO
/****** Object: StoredProcedure [dbo].[usp_GetNotGrabCard] Script Date: 01/17/2019 17:56:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[usp_GetNotGrabCard]--获取未抓取的充值卡
@cardType int,--接口ID
@Num int--每次获取充值卡数量
as
declare @Rowid table(rowid bigint);
BEGIN
set rowcount @Num; --一次读取的行数
--先将要读取的记录状态更新
update dbo.T_CardList set GrabState=2,GrabTime=CONVERT(nvarchar(50), GETDATE(), 20) output deleted.ID into @Rowid Where GrabState=1 and CardType=1
--读取刚更新状态的记录
select ID,CardNumber,CardPassword from T_CardList where ID in (select Rowid from @Rowid) and CardType=1;
END
GO