Is their any simple way to auto generate a project id like 0001, 0002, 0003 but instead of 0001 its 2014-0000001, 2014-0000002, 2014-0000003 ...
UserID = {YEAR}-{0000001} > continuous.
Sample:
UserID | Name
2014-0000001 | Gary
2014-0000002 | Alrey
or generating a csharp/c# function is much easy then manully inserted to table then get the latest UserID and increment but base on year? what can you suggest.
i have here sql command working but when the year pass by it wont reset to 1. i have an idea when counting rows where year is current date.
CREATE TABLE Test(
TestID INT IDENTITY(1,1) NOT NULL,
TestPrefixID AS (CONVERT([VARCHAR], YEAR(CURRENT_TIMESTAMP), 0)) + '-' + RIGHT('000000'+CONVERT([VARCHAR],TestID,0), (6)),
Name VARCHAR(100) NOT NULL,
CONSTRAINT PK_Teacher PRIMARY KEY (TestID)
)
thanks in advance.