I am repeating the same query over and Over.Is there a way i can create a function in the following query and pass as parameter to make it more readable.
USE [ES]
GO
DECLARE @current_value AS BigInt;
DECLARE @s nvarchar(1000);
SELECT @current_value = (SELECT sequence_id FROM SEQUENCES where seq='seq1')
if (@current_value > '0')
SET @s = N'
ALTER SEQUENCE seq1 RESTART WITH ' + CAST(@current_value AS nvarchar(10));
EXEC (@s);
SELECT @current_value = (SELECT sequence_id FROM SEQUENCES where seq='seq2')
if (@current_value > '0')
SET @s = N'
ALTER SEQUENCE seq2 RESTART WITH ' + CAST(@current_value AS nvarchar(10));
EXEC (@s);
SELECT @current_value = (SELECT sequence_id FROM SEQUENCES where seq='seq3')
if (@current_value > '0')
SET @s = N'
ALTER SEQUENCE seq3 RESTART WITH ' + CAST(@current_value AS nvarchar(10));
EXEC (@s);
GO