I imported the Software PAD File Database from http://paddatabase.net/download.html into Microsoft Access in a table called main:
MAIN
-----
ID
ProgramName
Program_category_Class
CategoryID <- I created this to create a one to many relation with a new table Category
.
.
I created two new tables: category and subcategory.
Category
--------
ID
CategoryName
I extracted all the values from the field Program_Category_Class on the left side of the :: delimiter into the Table Category. Data from Program_Category_Class looks like this:
Program_Category_Class
Business::Accounting & Finance
Games & Entertainment::Action
Business::Accounting & Finance
Business::Databases & Tools
What I want to do is create a SQL Query which Updates the MAIN table with the Category ID from the Category table that is a LIKE (Left) match on Program_Category_Class. I will then modify the query for a right left match for the subcategory table.
I tried something like thi开发者_开发百科s but get no result:
UPDATE Main SET Main.category = (SELECT Category.ID
FROM Category
WHERE Category.CategoryName LIKE Main.Program_Category_Class+'%')
WHERE (((Exists (SELECT Category.ID
FROM Category
WHERE Category.CategoryName LIKE Main.Program_Category_Class+'%'))<>False));
As it is a public DB I can provide a copy of the database to anyone interested.
Any assistance would be most appreciated. Thank you.
You may wish to remove <>False
, as well as some of the extra parenthesis. That's not your real problem, but it will help with readability. No, what's happening is that your like predicate is effectively backwards - you're trying to compare the longer question with the shorter answer. Switch the where clause to WHERE Main.Program_Category_Class like Category.CategoryName + '%'
and see if that helps.
Also, you are trying to update Main.category
, when the new field looks to be named Main.CategoryID
.
For future reference, please consider these common helpful followups to provide: So what do you mean you get no results? Does the query complain that it's not valid (which it should, if the field names are an issue), or does it not updated any rows?
精彩评论