Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
Help with Stored Function
Old
  (#1)
Guest
Guest
 
Posts: n/a
Default Help with Stored Function - 06-04-2007, 07:48 AM

I am trying to create the following stored function. There are only 2
queries in the function and I have tested both successfully on their
own. The error message I receive when I try to create the function
(using Query Browser) is the following:

You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'END' at
line 31 - ErrorNr. 1064

I am using server 5.0.22. Any help would be greatly appreciated.
Thank You.

DELIMITER \\

DROP FUNCTION IF EXISTS `iw`.`getInvoiceStatus`\\
CREATE FUNCTION `iw`.`getInvoiceStatus` (id INT) RETURNS INT
BEGIN
DECLARE done, partial INT DEFAULT 0;
DECLARE oiID, oiQty, iiQty INT;
DECLARE full INT DEFAULT 1;
DECLARE oiCursor CURSOR FOR SELECT orderitemID, qty FROM orderitem
WHERE orderID = id;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
OPEN oiCursor;
loop1: LOOP
FETCH oiCursor INTO oiID, oiQty;
IF done THEN
Close oiCursor;
LEAVE loop1;
END IF;
SELECT IF(SUM(invoiceitem.qtyInv) IS NULL, 0,
SUM(invoiceitem.qtyInv)) INTO iiQty FROM invoiceitem WHERE orderitemID
= oiID;
IF iiQty > 0 THEN
SET partial = 1;
END IF;
IF iiQty < oiQty THEN
SET full = 0;
END IF;
END LOOP loop1;

IF partial = 0 THEN
RETURN 0;
ELSE IF full = 0 THEN
RETURN 1;
ELSE
RETURN 2;
END IF
END\\

DELIMITER ;


- Matt

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top