How do I write multiple conditions in an MySQL IF statement?

I am using version 3.23 and want to write something like this:

If (date1 = ‘0000-00-00’ AND date2 = ‘0000-00-00’ ) {
status = "status1;
} elseif (AND order_date1 != ‘0000-00-00’ AND date3 = ‘0000-00-00’ AND date2 = ‘0000-00-00’ ) {
status = "status2;
} elseif () {

How would write something like that in a MySQL IF?

I know the structure is:

IF(expr1,expr2,expr3)

So for exp3 do you put that in parentheses and start over with another IF? Any examples of 5-6 layers of IF statements would be very helpful.

Would CASE WHEN be a better control flow structure?

Many thanks!

CASE is better because it is standard SQL, IF is proprietary to mysql IIRC.

can you give me an example of how to start writing this - I don’t want someone to write it for me but just an example of how to write more than two cases in a CASE WHEN.

Thanks.

example:

CASE WHEN stooge = 'curly'
     THEN 'nyuk nyuk'
     WHEN stooge = 'larry'
     THEN 'hey moe'
     WHEN stooge = 'moe'
     THEN 'spread out'
     ELSE 'whatever'    END

when would stooge not be curly, larry, or moe? when it’s shemp, joe, or curly joe :wink:

great example - thanks for the laugh too

Do you remember about 20 years ago there was a “3 stooges” hit song? "Hey Moe!, Hey Moe, Well a yuk yuk yuk, <chorus> “well a yuk yuk yuk”.

the curly shuffle (wait for page to load)

yep - that’s the classic!