Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Update table from an lookup table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-09-04, 06:47
inetgnu inetgnu is offline
Registered User
 
Join Date: Jun 2004
Posts: 2
Smile Update table from an lookup table

Hello,

I have the following problem of getting the SQL statement of the following
task:

table 1: part_of_car
--------------------------------------------------
pid | pdesc | pcategory
--------------------------------------------------
100 | AR-R8-4D NSK BEARING |
200 | 110-702-3S WATER PUMP |
300 | 1764-FJ-3 DISC BRAKE PAD KIT |
400 | INSULATOR ENG KTB |
...


table2: category
------------------------------
cid | keyword | desciptiontext
------------------------------
1 | CYL | Cylinder
2 | BRK | Brake
3 | ENG | Engine
4 | BUM | Bumper
5 | BEA | Bearing
6 | PUM | Pump
...


The problem is to search the 'pdesc' column of 'part_of_car' table containing
the text of each of value of the 'descriptiontext' of the 'category' table and UPDATE 'part_of_car'.'pcategory' column with the corresponding 'keyword' column of the 'category' table.


The UPDATED 'part_of_car' Table is expected to be :


pid | pdesc | pcategory
-------------------------------------------------
100 | AR-R8-4D NSK BEARING | BEA
200 | 110-702-3S WATER PUMP | PUM
300 | 1764-FJ-3 DISC BRAKE PAD KIT | BRK
400 | A4-BT INSULATOR ENGINE | ENG

Thank you for your help in advance.

Regards
Reply With Quote
  #2 (permalink)  
Old 06-09-04, 09:55
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 2,717
What if part_of_car.pdesc contains two (or more) category.descriptiontexts? For example, "1764-FJ-3 ENGINE BRAKE PAD KIT" (never mind this example means nothing in real life). What would you take as a result for part_of_car.pcategory? ENG or BRK?

If those tables contain a few data, I guess result will be more accurate if you do it yourself (scroll through data and mark them).
But, if it is impossible, I'm afraid you might have a table full of garbage.

However ... I'd say you need two nested loops: first would read part_of_car table and extract, as substrings, words of pdesc column ("110-702-3S WATER PUMP " = "110-702-3S" + "WATER" + "PUMP") and then, in another loop, compare that substring with all the category.descriptiontext values. If they match, update part_of_car table with the category.keyword you've found.

Quite simple, actually ... If that's what you need, of course
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are On
Pingbacks are On
Refbacks are On