我写过的一个SP
CREATE PROCEDURE epcPasswordIsLastNUsed
@epcUserID int,
@NewPassword VARCHAR(50),
@LastN Varchar(5)
AS
declare @sql nvarchar(200)
declare @IsUsedLastN int
set @sql = 'If ''' + @NewPassword + ''' in
(Select top ' + @LastN + ' [Password] from epcPassword
Where epcUserID = '+ CAST ( @epcUserID AS varchar(10) ) +' Order By epcPasswordID Desc)
Set @IsUsed =1 else set @IsUsed = 0'
exec sp_executesql @sql,N'@IsUsed int output',@IsUsedLastN output
return @IsUsedLastN
GO
GRANT EXECUTE ON [dbo].[epcPasswordIsLastNUsed] TO [public]
GO