#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Help needed with stored procedure


    Hi,

    I'm debugging this procedure that has a syntax error.
    I don't find anything wrong with it. can someone take a look?

    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
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,179
    Rep Power
    4279
    what a horrible stored procedure, i hope it wasn't you that wrote it

    notice that it doesn't do anything

    you can safely discard it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo