So we had to make some assumptions.
- Your sequential number will be 1 through 999 and then reset back to 1
- Your first set of letters is user definable through a variable up to 40 characters long
- Your dropdown will be up to 40 characters long
First we start by creating a Sequence in your SQL DB
CREATE SEQUENCE dbo.AlcosebaSequence
AS INT
START WITH 1
INCREMENT BY 1
MINVALUE 1
MAXVALUE 999
CYCLE
NO CACHE;
GO
Now we can call the next value from the sequence, so we create our Stored Procedure like:
CREATE PROCEDURE dbo.spAlcosebaSequence
@Leading VARCHAR(40),
@DropDown VARCHAR(40)
AS
BEGIN
SELECT (@Leading + '-' + CAST(YEAR(GETDATE()) AS VARCHAR(4)) + '-' + RIGHT('00' + CAST(MONTH(GETDATE()) AS VARCHAR(2)),2) + '-' + @DropDown + '-' + RIGHT('000' + CAST(NEXT VALUE FOR dbo.AlcosebaSequence AS VARCHAR(3)),3)) AS AlcosebaSequence;
END
