Click here to Skip to main content
16,017,151 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
Dear i want to generate user specific auto increment code . like

i m creating a lead sheet . than when we submit and save it in database its id should be create like this : LS_001 for next entry . it should be , LS_002
Posted

can you please check it out this...

Auto-incremented ID with NVARCHAR/VARCHAR datatype[^]

you need to work around and need to change accordingly to your requirement.
 
Share this answer
 
v2
Try like this

SQL
CREATE      TABLE dbo.TestTable
( ID INT IDENTITY(1,1) PRIMARY KEY,
name int ,
  FormatColumn AS RIGHT('LS_00' + CAST(ID AS VARCHAR(8)), 6) PERSISTED
)

insert into TestTable ( name) values (1)
insert into TestTable ( name) values (2)
insert into TestTable ( name) values (3)

select * from TestTable
 
Share this answer
 
Comments
Rohit85 28-Jan-14 2:23am    
This Is Successfully Run .
Rohit85 28-Jan-14 5:02am    
Karthik tell me one thing if i run this code to Ms Access Data base it will run with same code or i have to change some where

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