I don't know why you want to do this, but looking at your sybtax, it seems like you come
from a Sybase or SQL Server environment. What you are trying to achieve is the
way it is done in Transact SQL, where the conditional statements and stuff like that which
are typically used in stored procedures, may also be used outside stored procedures.


As someone else suggested, a real programming environment might be more appropriate,
with a MySQL connection. Like Perl or so.


Depite this, the simple example you may well be done with reasonably normal SQL in MySQL
like this:


select IF(@val = 1,'It is 1', 'It is not one');

But I suspect you want something more advanced than this, as this is not the most useful program the
world has seen. (But not the least useful either).


/Karlsson
Luke Venediger wrote:

Hi,

I'm trying to write a conditional statement in my query. Is the
following possible in MySQL?

IF(@SomeValue = 1)
THEN
SELECT "The value is 1";
ELSE
SELECT "The value is not 1";
END IF

I've tried different variations and nothing seems to be working (I'm
getting syntax errors). I'm using MySQL 4.0.18. Any help would be
greatly appreciated.

Thanks,
Luke Venediger.




-- __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Anders Karlsson ([EMAIL PROTECTED]) / /|_/ / // /\ \/ /_/ / /__ MySQL AB, Sales Engineer /_/ /_/\_, /___/\___\_\___/ Stockholm <___/ www.mysql.com Cellphone: +46 708 608121


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to