Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 1 of 1 total
Thread I'm unsure if this JOIN is correct
Thu, Jan 11 2007 1:47 PMPermanent Link

Rolf Frei

eicom GmbH

I have this JOIN written and I'm not sure if it realy does what I want
(correct OR's?):

UPDATE Parts a
SET MainGroup = NULL, Category = NULL, SubCategory = NULL
FROM Parts a
JOIN groups b ON (b.maingroup = a.maingroup AND (b.category = a.category OR
b.category is NULL) AND (b.subcategory = a.subcategory OR b.subcategory IS
NULL))
WHERE b.enabled = 0

Here is what my groups table looks like:
[maingroup,category,subcategory],description,enabled (fields in [] is
primary key)
1,NULL,NULL,"Group 1",1
1,1,NULL,"Category 1.1",1
1,1,1,"Subcategory 1.1.1",1
1,2,NULL,"Category 1.2",1
1,2,1,"Subcategory 1.2.1",1
5,NULL,NULL,"Group 5",1
5,1,NULL,"Category 5.1",1
etc.

The parts table has references to this groups table. Now I must clear this
reference in parts, if one of the records in groups is disabled (controlled
by another field "enabled"). That means if the maingroup 1 gets disabled
(field enabled= 0) it must clear the maingroup, category and subcategory
fields in the part table for every record with the maingroup = 1 ignoring
the values of the category and subcategroy partfield. The same must be work
if we disable the category 1.2, so all record with maingroup = 1 and
category = 2 and ignoring the subcategory value in parts must be cleared.

Hopefully you have understand what I mean Smile
Does the above JOIN work as I expect? It seems so but im not sure if this
OR's in the JOIN are valid so.

Regards
Rolf

Image