[dbo].[SetSystemValidationByKey]
CREATE PROCEDURE [dbo].[SetSystemValidationByKey]
@inNameKey varchar(16),
@inNewKeyValue varchar(512),
@inNewExpirationDateUtc datetime
as
set nocount on
declare @theRowCount int
update [Validation] set
KeyValue = @inNewKeyValue,
EffectiveDateUtc = getutcdate(),
ExpirationDateUtc = @inNewExpirationDateUtc
where NameKey = @inNameKey and
IsSystemValidation = 1
set @theRowCount = @@ROWCOUNT
if( @theRowCount != 1 )
begin
if( @theRowCount = 0 )
begin
insert into [Validation]
(
NameKey,
KeyValue,
EffectiveDateUtc,
ExpirationDateUtc,
IsSystemValidation
)
select
NameKey = @inNameKey,
KeyValue = @inNewKeyValue,
EffectiveDateUtc = getutcdate(),
ExpirationDateUtc = @inNewExpirationDateUtc,
IsSystemValidation = 1
where not exists( select top 1 1 from [Validation] where NameKey = @inNameKey and IsSystemValidation = 1 )
end
set @theRowCount = isnull( ( select top 1 ValidationID from [Validation] where NameKey = @inNameKey and IsSystemValidation = 1 order by ValidationID ), 0 )
delete from [Validation]
where NameKey = @inNameKey and
ValidationID != @theRowCount
end
GO
GRANT EXECUTE ON [dbo].[SetSystemValidationByKey] TO [MssExec]
GO