I want to generate random employee id
like "EMP" + "joined year"+####
for example EMP201410000
using C#
joined year take from dropdown list
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
ali tuncerRank #1,499 · 1.1K reputationPosted Mar 10, 2016, 7:19 PM EST
You can use Random class, but you should check if it is unique before saving..
http://www.c-sharpcorner.com/UploadFile/mahesh/RandomNumber11232005010428AM/RandomNumber.aspx
Naveenkumar Tholkappian100 reputationPosted Mar 15, 2016, 1:20 AM EDT
Kunal PatelRank #1,359 · 1.2K reputationPosted Mar 15, 2016, 2:06 AM EDT
Add one extra field EmployeeId in your table and apply this trigger(inside attachment) on your table
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @lastInsertedid INT
SET @lastInsertedid = ( SELECT IDENT_CURRENT('YourTableName')
)
--update employeeid field after value insert into table
UPDATE YourTableName
SET EmployeeId = 'EMP' + CONVERT(VARCHAR(50), YEAR(GETDATE()))
+ CONVERT(VARCHAR(50), @lastInsertedid)
WHERE Id = @lastInsertedid
END;