View Single Post

   
  #2 (permalink)  
Old 03-17-2008, 06:13 AM
Luuk
 
Posts: n/a
Default Re: Stored procedure problem with variable limit

Kim schreef:
> Im using MySQL 5.1 to create a stored procedure, but without luck.
>
> Query:
> DELIMITER /
> CREATE PROCEDURE _test()
> BEGIN
> DECLARE x INT;
> SET x = 5;
> SELECT * FROM tbl LIMIT x;
> END
>
> I get this error:
> #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 'x;
> END' at line 5
>
> ..and I have no idea why. Anyone knows why ?


try this:
SET @a=1;
PREPARE STMT FROM 'SELECT * FROM tbl LIMIT ?';
EXECUTE STMT USING @a;
(source: http://dev.mysql.com/doc/refman/5.0/en/select.html)


--
Luuk
Reply With Quote