Click here to Skip to main content
15,895,772 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to generate some formats in SQL server 2008 where i will provide the beginning serial number and number of records to be generated then the SQL should return the generated formats as per requirement.

For example my beginning serial number is 'AA-001' and i want 10 records then SQL should increment the beginning serial number and generate format like

'AA-002',
'AA-003',
'AA-004'

and so on.The twist here is i don't have any predefined format it can be anything like 'AA-22-555' ,'AA-1111' or even 'A1-01-1111' and the number of digits in each set will be constant.

For e.g.suppose while incrementing format 'AA-11-111' if it reaches to 'AA-11-999' then next serial number should be 'AA-12-999'.

Did anyone have ever done anything similar to this? Currently i have code but if works only for some predefined formats and i want it to be flexible to work with all formats.
Posted
Updated 29-Jul-14 4:14am
v2

1 solution

First of all, its not clear to me on what basis the next number should be AA-12-999 after AA-11-999.

Further, to generated auto numbers with customized format you should better see this : http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server[^]

Regards..
 
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