Hi,

I've got a syntax error with this stored procedure and I don't find what is wrong.
can someone take a look and help me please?

DELIMITER $$

CREATE DEFINER=`btUser`@`localhost` PROCEDURE `Notifications_GetByUserId`(
IN SiteId int,
IN UserId int,
IN FirstId int,
IN LastId int
)

BEGIN

declare tmpId1 int ;
declare tmpId2 int;

declare cur CURSOR FOR select uida,uidb from usersfriendship where siteId = SiteId and approved = 1 and (uida = UserId or uidb = UserId);


CREATE TEMPORARY TABLE IF NOT EXISTS tmpUsers (
userId int,
PRIMARY KEY (`userId`)
) ENGINE=MEMORY ;

open cur;
loopUsers: loop

fetch cur into tmpId1,tmpId2;
if tmpId1 = UserId then insert into tmpUsers (userId) values (tmpId1);
if tmpId2 = UserId then insert into tmpUsers (userId) values (tmpId2);

end loop loopUsers;
close cur;

END