MySQL Forums
Forum List  »  Newbie

IF ELSE
Posted by: Michael Smith
Date: March 15, 2023 03:31PM

I am trying to deal with cases where a new invoice is building but it needs an invoice number.

I have stored the next invoice number in a file called Storage01 in the field Nextra5.

The code below deals with this and is accepted by MySQL Workbench but when I try to run it I get an error "Not allowed to return a result set from a function". But if I remove the Function, I get other errors.

Any suggestions would be appreciated.


DELIMITER //
CREATE FUNCTION COUNT_ITEM (NINVS INT)
RETURNS INT

BEGIN

SELECT count(ITEM) FROM Invoices01 as NINVS where invnbr > 0 ;
IF NINVS = 0 THEN
SELECT @mnewnumber := Nextra5 from Storage01 ;
update Invoices01 set invnbr = @mnewnumber;
END IF;

END; //

DELIMITER ;

Options: ReplyQuote


Subject
Written By
Posted
IF ELSE
March 15, 2023 03:31PM
March 19, 2023 12:56AM
March 22, 2023 01:34PM
March 22, 2023 05:02PM
March 22, 2023 07:21PM
March 23, 2023 01:54AM
March 26, 2023 06:24PM


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.