I do not think any looping is required. You should be able to do this using sub queries within the where clause.
If you are using cfx_prod_custCat as a lookup table simply look for any category that is not listed in the custcat_id field: UPDATE Categories SET hasproducts = 0 WHERE category IN (SELECT DISTINCT category FROM Categories WHERE ID NOT IN (SELECT DISTINCT custcat_id FROM cfx_prod_custCat)) You use the same logic for the 2nd part of the UNION clause: UPDATE Categories SET hasproducts = 0 WHERE category IN (SELECT DISTINCT category FROM Categories WHERE category NOT IN (SELECT DISTINCT category FROM products)) Basically you use the sub query to pull a list of all products that have a category assigned and the look for categories that are not in that list. Hopefully I am not way off on this and it helps point you in the right direction. Brian Cain ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:341562 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

