Hi Anders, Thanks for that. Yes, I have come from an MSSQL environment, and I'm using .Net 1.1 with the MySQL Connector/Net. The idea behind using conditional statements was to assign a query to a business task. For example, I could write a query to handle adding items to a shopping cart. In the query, before I add the item, I need to check if the item is in stock. If it's not in stock, I need to return a result set that indicates there has been an error, i.e. "There is no stock of the requested item."
Putting this logic in my code means having to execute a number of statements with code checks in-between, where I would rather only execute one query. Cheers, Luke Venediger. On Fri, 22 Oct 2004 18:49:54 +0200, Anders Karlsson <[EMAIL PROTECTED]> wrote: > 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 > > -- Get Firefox Browser! Reclaim the web. http://getfirefox.com/ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]