I have the sql query below. I want to take the results and insert it into another table using the insert below. Is this a good choice for a stored procedure.
It doesn’t need to run very often, so no need to attach it to a trigger… I’ll probably just write a php script to trigger it via an hourly cron job. (or maybe I can trigger it via command line)
So, am I barking up the wrong tree on this one? Thanks Oh, I’ll accept any helpful answer.
SELECT
COUNT(*) AS thecount,
MAX(datetime_acc) AS DATE,
u.created_usr,
@payout:=IF(u.created_usr < '2011-01-24',20,10) AS payout,
level_usr,
@uid_usr:=p.uid_usr,
@affiliate:=u.affiliate_aff,
created_usr,
firstname_usr,
lastname_usr,
contact_aff,
c.id_com
FROM payment_acc p
LEFT JOIN users_usr u ON p.uid_usr = u.id_usr
LEFT JOIN commissions_com c ON c.uid_usr = u.id_usr
LEFT JOIN affiliate_aff a ON a.code_aff = u.affiliate_aff
WHERE p.type_acc = 'monthly payment'
AND affiliate_aff IS NOT NULL
GROUP BY p.uid_usr
HAVING thecount > 1
ORDER BY affiliate_aff
The INSERT:
Insert into commissions_com
date_generated_com,
amount_com,
uid_usr,
code_aff,
status_com
values
(NOW(),
@payout,
@uid_usr,
@code_aff,
'new')
What “value” are you looking for?
Jeff Atwood has for a long time questioned the use for stored procuedres.
From the mysql documentation:
From what you have described, your script doesn’t sound general or to be used for several tasks.
For the time being then, I would avoid a stored procedure.