tags:

views:

58

answers:

2
SELECT * FROM O_PLATI_DAUNE
WHERE 
     LUNA LIKE     
CASE
   WHEN LUNA = '7'  THEN SUMA ='363623.72'
   WHEN LUNA = '8'  THEN SUMA ='825159.25'
   WHEN LUNA = '9'  THEN SUMA ='182730.99'
   WHEN LUNA = '10' THEN SUMA ='361722.74'
   WHEN LUNA = '11' THEN SUMA ='1787574.67'
   WHEN LUNA = '12' THEN SUMA ='3605005.68'
ELSE 'N/A'
END 

I don't know why it doesn't work, please somebody help me!

Thanks a lot.

A: 

I believe this is for MySQL, so I would recommend reading the manual on CASE:

http://dev.mysql.com/doc/refman/5.1/en/case-statement.html

Look at the example a little further down the page - your case structure is off.

Case statements can't be used directly in the WHERE clause - trying to find an example, but no luck thus far.

DBA_Alex
+1  A: 

Are you trying to do something like:

SELECT id,LUNA,CASE
   WHEN LUNA = '7'  THEN '363623.72'
   WHEN LUNA = '8'  THEN '825159.25'
   WHEN LUNA = '9'  THEN '182730.99'
   WHEN LUNA = '10' THEN '361722.74'
   WHEN LUNA = '11' THEN '1787574.67'
   WHEN LUNA = '12' THEN '3605005.68'
   ELSE 'N/A'
   END as SUMA
 FROM O_PLATI_DAUNE 
nos