Groups | Blog | Home
all groups > sql server programming > january 2004 >

sql server programming : Help with Incrementing


J
1/28/2004 10:18:48 PM
Hi,
I'm using SQL 7 and I'm trying to automatically assign ID Numbers. The
numbers must be in an alphanumeric format using three letters and
incrementing five numbers.I have two sites where the letters represent the
site and the numbers represent the visitor. For instance:

Site A Site B

ABC00001 DEF00001
ABC00002 DEF00002
etc. etc.

I have a table called Sites and a table called Contacts

Sites Contacts
Site_ID Contact_ID
Site_Name Contact_Name
Site_Address Contact Address
.... ...
Site_Code

When we get a contact, I need to automatically assign the Contact_ID to the
three letter site code and five digit incrementing number starting with
00001

Can anyone help?

Thanks

J



Raharja
1/29/2004 12:26:10 AM
for example u have variabel @Site_ID as your site id, and @Contact_ID for your new contact i

SET @Contact_ID = @SITE_ID + RIGHT('0000' + LTRIM(Cast(((SELECT COUNT(contact_ID) FROM contacts where contact_id LIKE @SITEID + '%') + 1 )as varchar(5))),5

Regards

Uri Dimant
1/29/2004 8:03:56 AM
J
try it
select '0000'+cast(1 as varchar(10))


[quoted text, click to view]

AddThis Social Bookmark Button