使用SQL Server 2008生成自动增量格式 [英] Generate auto increment formats using SQL server 2008
问题描述
我必须在SQL server 2008中生成一些格式,我将提供开始的序列号和要生成的记录数,然后SQL应该按照要求返回生成的格式。
例如我的开始序列号是'AA-001'而我想要10条记录然后SQL应该增加开始的序列号并生成格式如
'AA-002',
'AA-003',
'AA-004'
这里的扭曲是我没有任何预定义的格式,它可以是'AA-22-555','AA-1111'或甚至'A1-01-1111'之类的,以及每个的数字位数设定将是恒定的。
对于egsuppose,如果达到AA-11-999,则递增格式'AA-11-111',则下一个序列号应为'AA-12 -999'。
有没有人做过类似的事情?目前我有代码,但如果只适用于某些预定义的格式,我希望它可以灵活地使用所有格式。
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.
推荐答案
首先,它不清楚在AA-11-999
之后,我的基础是AA-12-999
。
此外,要生成具有自定义格式的自动数字,您最好看到这一点: http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server [ ^ ]
问候..
First of all, its not clear to me on what basis the next number should beAA-12-999
afterAA-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..
这篇关于使用SQL Server 2008生成自动增量格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!