| Author |
Topic |
|
barnabeck
Posting Yak Master
236 Posts |
Posted - 2012-01-03 : 06:02:36
|
| Happy New Year!!!Every year on the first of January I have to manual reset ID's that create serial numbers and that are built on the running year. (eg. 120000 for this year by truncating the last 6 digits)In order to automize this process I tried a JOB with this commandDBCC CHECKIDENT('database', RESEED, year (getdate())*10000)whileselect year (getdate())*10000) gives the correct result, inserting it into the DBCC CHECKIDENT throws a syntax error. It seems that the command wont accept any expression to specify the reset-number.Anybody knows how to accomplish this?Martin |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-03 : 06:19:31
|
put the expression in a variable and use itie likeDECLARE @YearVal intSET @YearVal=year (getdate())*10000DBCC CHECKIDENT('database', RESEED, @YearVal)i didnt understand why you're reseeding it each year though. do you remove the data for previous years before you do this?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
barnabeck
Posting Yak Master
236 Posts |
Posted - 2012-01-03 : 07:19:23
|
| Thank you visakh, that was the way it finally worked!The data is not removed because the ID remains unique! We use this to create the running serial numbers for incomming repair orders and it is usefull to have this based on the year. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-03 : 07:33:05
|
| ok...but what guarantee you've that data in a year wont overflow and make generated id overshoot to next years value?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
barnabeck
Posting Yak Master
236 Posts |
Posted - 2012-01-03 : 08:28:41
|
| ok... I see what you mean. Well, experience shows that there wont be more than 3000 cases of RMA cases (returned defect material) in one year... once we have more than 9999 then our firm will have to close anyway ;) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-03 : 09:39:38
|
| hmm..ok...But is it worth taking risk?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
barnabeck
Posting Yak Master
236 Posts |
Posted - 2012-01-03 : 10:27:49
|
| well, whenever you define a standard for a serial code with x-digits you have that same risk. I'm using 4 digits and place the year in front limiting the system to 9999. If in the future I see that the 4 digits wont be enough to cover the incidents over one year I'll change to 5 digits by multiplying the following year with 100.000. Thanks for your interest and concerns, anyway. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-03 : 10:53:25
|
| ok...if you're confident, fine with that------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|