Gossamer Forum
Home : General : Databases and SQL :

Update records in a table based on a function

Quote Reply
Update records in a table based on a function
I am not sure if this can be done purely with SQL, or it will require a perl loop. I am guessing straight SQL is the better performace option.

I have the function (which you helped me write two posts agoWink):

#determine if the category has children
sub has_children { $DB->table('Category')->count( { FatherID => $_[0] } ) }

and I want to go through every record in Category, run the "ID" through my function: has_children($category_id), and if it returns true, SET Category.haschildren = "Yes" ELSE set "No".

UPDATE 'Category' SET 'haschildren' = 'Yes' WHERE has_children('ID') <- my bad attempt


http://www.iuni.com/...tware/web/index.html
Links Plugins
Subject Author Views Date
Thread Update records in a table based on a function Ian 14804 May 15, 2002, 10:46 PM
Thread Re: [sooke] Update records in a table based on a function
yogi 14711 May 16, 2002, 12:27 AM
Post Re: [yogi] Update records in a table based on a function
Paul 14489 May 16, 2002, 12:52 AM
Post Re: [yogi] Update records in a table based on a function
Ian 14534 May 16, 2002, 8:30 AM
Post Re: [yogi] Update records in a table based on a function
Ian 14519 May 16, 2002, 9:05 AM
Thread Re: [yogi] Update records in a table based on a function
Ian 14555 May 16, 2002, 10:22 AM
Thread Re: [sooke] Update records in a table based on a function
Paul 14577 May 16, 2002, 10:45 AM
Post Re: [Paul] Update records in a table based on a function
Ian 14519 May 16, 2002, 10:56 AM
Thread Re: [yogi] Update records in a table based on a function
Ian 14557 May 19, 2002, 4:37 PM
Thread Re: [sooke] Update records in a table based on a function
yogi 14527 May 20, 2002, 6:05 AM
Thread Re: [yogi] Update records in a table based on a function
Ian 14531 May 20, 2002, 8:33 AM
Thread Re: [sooke] Update records in a table based on a function
webmaster33 14551 May 20, 2002, 9:44 AM
Post Re: [webmaster33] Update records in a table based on a function
Ian 14415 May 20, 2002, 9:48 AM
Post Re: [sooke] Update records in a table based on a function
webmaster33 14457 May 20, 2002, 6:18 AM