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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kunal PatelPosted Mar 15, 2016, 6:06 AM
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;
Naveenkumar TholkappianPosted Mar 15, 2016, 5:20 AM
ali tuncerPosted Mar 11, 2016, 12:19 AM
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