Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

OT : MySQL statement question



tbs wrote:
> What I was wondering is, can I do this :
> 
> select t.a, t.b, t.c, t.d
> from table 't'
> where
> ta. = 'foo'
> and t.b = 'bar'
> IF (cond) THEN
>     AND isNULL(t.c)
> ELSE
>     AND t.c in(vINPUTLIST)
> ENDIF;

It should be possible to avoid repeating the long SQL statement twice
using one of two possible techniques:

1. Write your WHERE clause using IF() or other functions (functions, not
flow control statements, as you show above) such that it always returns
true when the supplied vINPUTLIST is NULL.

2. Build your SQL as a string, as illustrated in this thread:
http://forums.mysql.com/read.php?98,395690,395690#msg-395690
This is much as you would do in an application language, and in this
case you can use flow control statements. Though this approach might
subvert some of MySQL's optimizations.


> well I have googled until my eyes are bleeding but cannot get a
> definitive answer on this one ...

Try the MySQL Stored Procedures Forum:
http://forums.mysql.com/list.php?98

 -Tom

-- 
Tom Metro
Venture Logic, Newton, MA, USA
"Enterprise solutions through open source."
Professional Profile: http://tmetro.venturelogic.com/






BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org