Skip navigation links

MySQL Forums :: Stored Procedures :: Stored Proc my 1st attempt.. feedback please


Advanced Search

Stored Proc my 1st attempt.. feedback please
Posted by: Dav Singh ()
Date: April 10, 2012 01:38PM

Hi Everyone,
my first post, have been reading and learning about stored proc, and would appreciate any feedback on this stored proc, it does everything it should, any constructive criticism /improvement etc would be much appreciated.
Thank you in advance
D


########


CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_DoReturnHistoryRecent`(IN `p_GUID` VARCHAR(255))
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN

DECLARE p_GUID_CHECK INT DEFAULT 0;

SELECT count(guid) INTO p_GUID_CHECK FROM mood WHERE mood.guid = p_GUID LIMIT 1;

IF p_GUID_CHECK >= 1 THEN

SELECT
SUM(weight)/COUNT(*) AS 'WEIGHT',
DATE_FORMAT( FROM_UNIXTIME(date), '%Y') AS Y,
DATE_FORMAT( FROM_UNIXTIME(date), '%m') AS M,
DATE_FORMAT( FROM_UNIXTIME(date), '%d') AS D
FROM
mood
INNER JOIN
mood_weights ON mood.mood_id = mood_weights.mood_id
WHERE

mood.guid = p_GUID
AND
FROM_UNIXTIME(date) > DATE_SUB(CURDATE(), INTERVAL 7 DAY)
GROUP BY DAYNAME(FROM_UNIXTIME(date))
ORDER BY date ASC;

END IF;
END

Options: ReplyQuote


Subject Views Written By Posted
Stored Proc my 1st attempt.. feedback please 1247 Dav Singh 04/10/2012 01:38PM
Re: Stored Proc my 1st attempt.. feedback please 868 Peter Brawley 04/10/2012 01:59PM
Re: Stored Proc my 1st attempt.. feedback please 581 Rick James 04/23/2012 09:44PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.