A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Assigning ID by group



 
 
Thread Tools Display Modes
  #1  
Old March 26th, 2008, 07:06 AM posted to microsoft.public.access,microsoft.public.access.queries
John
external usenet poster
 
Posts: 308
Default Assigning ID by group

Hi

I have a table of contacts with their associated companies. How can I assign
numeric company ids in sequence to these records such any records with the
same company names get the same company ids?

Thanks

Regards


  #2  
Old March 26th, 2008, 10:49 AM posted to microsoft.public.access,microsoft.public.access.queries
Brendan Reynolds
external usenet poster
 
Posts: 1,241
Default Assigning ID by group

"John" wrote in message
...
Hi

I have a table of contacts with their associated companies. How can I
assign numeric company ids in sequence to these records such any records
with the same company names get the same company ids?

Thanks

Regards



Assuming the following tables and columns ....

Companies (CompanyID, CompanyName)
Contacts (ContactID, CompanyName, etc.)

First add a CompanyID field to the Contacts table, then run an update query
like the following ....

UPDATE Contacts INNER JOIN Companies ON Contacts.CompanyName =
Companies.CompanyName SET Contacts.CompanyID = [Companies].[CompanyID];

BTW, it would be a mistake to have both CompanyID and CompanyName in the
Contacts table. I'm assuming that you're planning on removing the
CompanyName column from the Contacts table after the CompanyID column has
been added and updated.

--
Brendan Reynolds

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:26 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.