August 14, 2009 at 8:13 am
you cannot reuse the numbers if there are gaps...at least not easily.
assuming you want a 10 digit number, ie 1 with 9 preceeeding zeros:
'0000000001'
Alter Table MyTable Add MyCalculatedColumn As RIGHT('0000000000' + convert(varchar(30), MyOriginalColumn),10) PERSISTED
the PERSISTED command maes the value be stored in the table...so you could create an index on it to make it easily searchable
Lowell
August 14, 2009 at 9:13 am
Lowell (8/14/2009)
you cannot reuse the numbers if there are gaps...at least not easily.
I'd like to add to that.... there is no reason to "fill in the gaps". If a given number is missing, so what? That only time that it may matter is if you are using ID cards that have preprinted numbers on them. Is that the case here?
--Jeff Moden
Change is inevitable... Change for the better is not.
August 14, 2009 at 1:04 pm
Thanks again guys!
Too bad SQL 2000 doesn't have PERSISTED. I created a column, but it only changed pre-existing ones, and not new ones.
As for filling in the gaps... I'm more concerned about the remote possibility of running out of 9 digit numbers. There is a lot of unused space... but the current largest number is somewhat close to the limit relatively speaking. But again the chance of that happening is still pretty low... unless someone did some mass inserts, then deletions a few times to run up the index.
Though not 100% fool proof, I tried out an insert trigger based upon your two column principle. Seems to work great with single inserts.
Viewing 3 posts - 31 through 32 (of 32 total)
You must be logged in to reply to this topic. Login to reply