November 9, 2007 at 1:48 pm
Hi,
I'm developing vb6 and ms sql2k application. I'd like identity column to look like '001', '002', or 'SS003'. These IDs are unique. I'll have a multiple users. Is there any way to create IDs automatically in the database? Thank you.
Dong
November 9, 2007 at 4:12 pm
See http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server
N 56°04'39.16"
E 12°55'05.25"
November 9, 2007 at 5:23 pm
Heh... or, you could just shoot yourself in the head now and save on the anticipation 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
December 2, 2007 at 4:28 pm
Don't do this. USe an identity, add a 2nd computed column if you must that pads things out with the 0s (meaning it's a char ) col.
SQL handles this well. You have a good chance of messing things up.
December 2, 2007 at 4:52 pm
Sorry for my bit of sarcasm... you do realize that you get 999 ID's and that's it, don't you?
--Jeff Moden
Change is inevitable... Change for the better is not.
December 2, 2007 at 4:53 pm
The best way to do this is to have an identity column and then have a calculated column that adds whatever prefix you need to the identity. If you really need to avoid the calculated column for some reason, you can add an on insert trigger that adds that column's value based on the current max, but you will get greater efficiency from the computed column and identity.
---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
December 2, 2007 at 5:09 pm
The best way to do this is to not do it at all... OP wants to limit the number of ID's to 999.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 3, 2007 at 7:43 am
As soon as you limit it, someone will come along and ask for more.
You could easily do this with an identity and set a trigger to stop anything after 999. Or find the holes and insert there, or do any number of things.
As Jeff said, the easiest way is not to do this.
December 6, 2007 at 7:48 am
It sounds like you want to see the data in a different way than it is stored. In that case, just use a format statement when you retrieve the data. You could set up a view to do this. Then when you go beyond 999 you could change the format.
Steve
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply