Variable in select top

Variable in select top

am 11.04.2006 06:40:44 von Harpreet

=20
I am trying to run sql select using a variable but with no luck

Select top @max_limit * from table but it doesnto work. Please help


--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org

Re: Variable in select top

am 11.04.2006 15:32:59 von Shawn Green

--- Harpreet wrote:

>
> I am trying to run sql select using a variable but with no luck
>
> Select top @max_limit * from table but it doesnto work. Please help
>
>

That's because you are trying to write a MS-specific SQL command. MySQL
doesnt have the TOP modifier. It uses a LIMIT clause at the end of the
SELECT statement.

http://dev.mysql.com/doc/refman/4.1/en/select.html

LIMIT clauses only work with constant values. If you do not create the
SELECT...LIMIT statement as a fully formed string (in the
programming/scripting language that you are using to execute your
statements) or use a replaceable parameter in a prepared statement
(v5.0+), you will not be able to use a variable value for the LIMIT
clause.

http://dev.mysql.com/doc/refman/5.0/en/sqlps.html

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine



__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org