I want to create a auto generate unique Id which contains today's date, month, year and some number.
Ex. in year 2016-only 16 will be used,
for the month of January 01 will be used,
for today's day 26 would be used,
and the slno is starts 0001 to 9999
So my id should be like 1601250001.
The date changes everyday and number should be increases ..
I Have tried ..
Create procedure InsertRegistration
(
@name nvarchar(50),
@Address nvarchar(100)
)
as
begin
DECLARE @BdID VARCHAR(25)
SET @BdID = (SELECT convert(varchar, getdate(), 112))+
CAST(((SELECT COUNT(*)
FROM BasicInformation
WHERE @BdID like (SELECT convert(varchar, getdate(),112))+'%')
+1 ) AS VARCHAR(5))
Insert into BasicInformation(BdID, name, address)
values (@BdID, @name, @address)
end
It's working but the increment is not happening for each registration. I am a beginner. Please help me