Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have somewhat of an odd situation

Status
Not open for further replies.

ronwmon

Programmer
Jul 13, 2007
97
US
I have somewhat of an odd situation.

I have a table titled working. In addition to many fields one contains a dealer ID. We want the dealer ID to be a number however sometimes a dealer enters their name instead of their dealer number. The service provider we use to manage this accepts either.

When we get a name instead of a number from our service provider the dealer ID will always start with “* “, that’s asterisk space then the dealer name.
For example, “* Dealer Name”.

We have a query that will select the distinct dealer names based on this criteria. The query inserts the dealer name in a table that has two fields, DelID and DealerID. We manually enter the dealer number in the DelID field.

INSERT INTO dealid ( dealerid )
SELECT DISTINCT (Working.dealerid)
FROM Working
WHERE left(dealerid,1) = chr(42);

Please note, in some cases a single dealer will have more than 100 individual entries in a single month.

Now, if next month we have a new dealer name entry we don’t want to recreate the DealID table, we only want to add the new dealer name to the DealID table. We will then manually add the dealer number for this new dealer name.

We have a query that changes the DealerID in the working table using the data in the DealID table.

UPDATE working INNER JOIN DealID ON [working].[dealerid] = [dealid].[dealerid] SET working.dealerid = [dealid].[delid]
WHERE [dealid].[dealerid] = [working].[dealerid];

We am struggling to write a query that will only add DealerID’s (dealer name) to the DealID table if the DealerID does not exist in the DealID table.

We want to continue to add to the DealID table as necessary and use this table to change the working.DealerID to the dealer number each month.

Any assistance is appreciated.

Ron--
 
a query that will only add DealerID’s (dealer name) to the DealID table if the DealerID does not exist in the DealID table"

[tt]INSERT INTO dealid ( dealerid )
SELECT DISTINCT (Working.dealerid)
FROM Working
WHERE left(dealerid,1) = chr(42)[blue]
AND Working.dealerid NOT IN (Select dealerid from dealid)[/blue]
[/tt]


---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top