I’m working on some code, and got stuck on this stored procedure problem… Have spent too long now looking at it, so please if someone can tell me where I am a noob with this.
I get the following error:
Error Code: 1064
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 ‘@ownerid varchar(50);
declare @active tinyint;
declare @subuser tinyint;
set ‘ at line 4
on this code:
DELIMITER //
USE `test`//
DROP PROCEDURE IF EXISTS `getAccount`//
CREATE DEFINER=`peter`@`%` PROCEDURE `getAccount`( IN cid VARCHAR(20))
BEGIN
DECLARE cardid VARCHAR(50);
DECLARE @ownerid VARCHAR(50);
DECLARE @active TINYINT;
DECLARE @subuser TINYINT;
SET cardid = MD5( cid + SHA1(cid + 'a salt value'));
SELECT @active = active, @ownerid = ownerid, @subuser = subuser FROM cards_tbl WHERE cardhash = cardid;
IF @active = 1 THEN
IF @subuser = 1 THEN
SELECT subuser_m2s_tbl.name,subuser_m2s_tbl.image, user_saldo.saldo AS credits FROM subuser_m2s_tbl
JOIN user_saldo ON subuser_m2s_tbl.subhash = user_saldo.userhash
WHERE subuser_m2s_tbl.subhash = @ownerid;
ELSE
SELECT user_m2s_tbl.name,user_m2s_tbl.image, user_saldo.saldo AS credits FROM user_m2s_tbl
JOIN user_saldo ON user_m2s_tbl.userhash = user_saldo.userhash
WHERE user_m2s_tbl.userhash = @ownerid;
END IF;
END IF;
END$$
DELIMITER ;
Am new to the stored procedures, so it is properly something very simple…..
Thanks in advance
You should use ‘:=’ instead of ‘=’ when you want to pass value into variable in SELECT statement, otherwise MySQL just will compare to operands.
Also you can use SELECT INTO statement, e.g. –
SELECT syntax.