Click here to Skip to main content
15,895,827 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Creating a table ClientInfo, in this i want to generate a alphanumeric code for ClientCode column. The Code whic i want to generate should be like SAPL-LPS-00001
SAPL is a static four letter string.
LPS is first three letter of organization.
00001 is incremented on the basis of identity column.
for this i have wrote some code in create table wizard but i am getting an error. I am sending my create table code to you.
One more thing OrganizationName coming from front end.

SQL
Create table ClientInfo
(
ClientId int identity(1,1) primary key,
ClientCode As ('SAPL-' +Right(substring(OrganizationName, 1,3) +Right('00000' +Convert(varchar, ClientId,0),(5)),3),
OrganizationName varchar(100))
Posted
Updated 31-Aug-14 22:01pm
v2

Use this in update query in trigger after insert
SQL
'SAPL-' + substring(OrganizationName, 1, 3) + '-' + Right('00000' + Convert(varchar, ClientId, 0), (5))
 
Share this answer
 
Comments
Member 10276989 1-Sep-14 6:00am    
Error saying right function have only two arguements if i try this

ClientCode As ('SAPL-' +Right(substring(OrganizationName, 1,3) +'-'+ Right('00000' +Convert(varchar,Clietid,0),(5)))),

@Vinay Mistry
 
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