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 14959 May 15, 2002, 10:46 PM
Thread Re: [sooke] Update records in a table based on a function
yogi 14863 May 16, 2002, 12:27 AM
Post Re: [yogi] Update records in a table based on a function
Paul 14641 May 16, 2002, 12:52 AM
Post Re: [yogi] Update records in a table based on a function
Ian 14686 May 16, 2002, 8:30 AM
Post Re: [yogi] Update records in a table based on a function
Ian 14671 May 16, 2002, 9:05 AM
Thread Re: [yogi] Update records in a table based on a function
Ian 14708 May 16, 2002, 10:22 AM
Thread Re: [sooke] Update records in a table based on a function
Paul 14729 May 16, 2002, 10:45 AM
Post Re: [Paul] Update records in a table based on a function
Ian 14671 May 16, 2002, 10:56 AM
Thread Re: [yogi] Update records in a table based on a function
Ian 14709 May 19, 2002, 4:37 PM
Thread Re: [sooke] Update records in a table based on a function
yogi 14679 May 20, 2002, 6:05 AM
Thread Re: [yogi] Update records in a table based on a function
Ian 14683 May 20, 2002, 8:33 AM
Thread Re: [sooke] Update records in a table based on a function
webmaster33 14706 May 20, 2002, 9:44 AM
Post Re: [webmaster33] Update records in a table based on a function
Ian 14567 May 20, 2002, 9:48 AM
Post Re: [sooke] Update records in a table based on a function
webmaster33 14610 May 20, 2002, 6:18 AM