using SELECT and case expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

using SELECT and case expression

Post by pelegk2 »

i want in the select sentence to check which month is the current date and by that to return the value.
for example if the current month is '02' then the returned values is '1' (for teling me that month 02 is in quarter 1!)
i tried to do

Code: Select all

select * from order_header where order_id=532 and case from_unixtime(done_date,'%m') when '02' then 'feee' END;
but got an empty line!
any idea why?
thnaks in advance
peleg
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

the case belongs in this case in the select clause, not the where clause....

(untested)

Code: Select all

select 
 *,
 case from_unixtime(done_date, '%m')
   when 2 then 'feee'
   else 'default'
 end
from order_header 
where order_id=532;
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

ooops thnaks alot:):)

Post by pelegk2 »

:):)
Post Reply