Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all

Please help me creating company code in below format

Company Name: xyzabc textile
code : xyza0001

i wrote the below query to get the substring
SQL
SELECT CompanyName, SUBSTRING (CompanyName, 0, 5) as substring_name
FROM Company
ORDER BY 1


But not getting how to add the counter with the query and result out the code in vb.net.

Please give some suggestion...
Posted

1 solution

You could have a separate table that stores the next companyNumber to use. then append that to the end of the string. If you did this in SQL when you insert the record it would prevent multiple clients getting the same number.

Each time the InsertCompany statement runs, you read the current number, append it to the code value you want to use and increment the number by one.
 
Share this answer
 
Comments
[no name] 7-May-13 7:54am    
can u give me some example for this...then it will be easy for me to understand..
Pheonyx 7-May-13 8:01am    
Insert into CompanyTable
Set
CompanyName = @CompanyName
Code = CONCAT((SUBSTRING (CompanyName, 0, 5) ), Select NextCompanyNumber from CompanyNumberTable)

Update CompanyNumberTable Set NextCompanyNumber = NextCompanyNumber+1


Something like the above might do the job.

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