Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on ASP.Net using C# I want to generate a sequence id that should be like this:
ELG0001 , ELG0002, ...

ELG is the PREFIX and 0001 should be in sequence.

I am using sql server 2005. This id will be generated and added to my database. how can i do?
Posted
Updated 24-Jul-10 21:02pm
v6

1 solution

OPTION 1:
Create an ID field in your database. Keep it as Integer type and auto-increment by 1 each time. (this can be done in DB very easily while setting up a table!)

Now since, its just the fixed letter 'ELG', append that whenever you are using them either in query while fetching data or in UI while using it whereever suits you.

OPTION 2:
Create an ID, TempID field in your database. Keep ID field as nvarchar(10) type and TempID field as Ineger type and auto-incrementable by 1.

Now, at the time of inserting record in table:
    1. You can put up on ID field that insert "ELG"+TempID.
    2. OR You can use TRIGGER to insert value


For having sequential numbers, you can have any logic you like. You can even pass it from frontend.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900