That's what I though.
In Transact SQL this is valid code to run on the server, and you may optionally
choose to put it all into a single stored procedure. In most other databases, a stored
procedure has a language that is not executable outside the procedure code itself.
With MySQL there will be stored procedure support in version 5.0 of the Server, but in
your case the 5.0 alpha will not help, as stored procedure calls probably has an issue or two
with the .NET provider.
Frankly, the way Sybase does this (which was later inherited by SQL Server) was
the way you did things at that time. It's just procedural code, the only difference being that
is runs on the server. Today, you would probably put this type of logic in a stored procedure or an
appserver. None of these is an option for you, so I guess that you have to put it in your code.
Really, it's not that much of an issue, and the performance gains from those days or doing things this
way are way less now.
In some cases, cleaver SQL constructs can be used for simple conditional processing, but it's not
generally applicable.
Good luck to you /Karlsson Luke Venediger wrote:
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
-- __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / 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]