Bookmark and Share
MySQL case statement
(Publish Date: 2009-10-4 1:46pm, Total Visits: 4510, Today: 1, This Week: 4, This Month: 11)

1. An example of case statement in the procedure:

delimiter //
 create procedure migrate_total (norID int)
 begin
         DECLARE euID INT DEFAULT 1;
         DECLARE saveTime datetime DEFAULT '2009-09-01';
         CASE norID
       WHEN 2279 THEN
        set euID=35;
                set saveTime = '2009-01-01';
       WHEN 1003 THEN
        set euID=38;
                set saveTime = '2009-01-01';

         END CASE;
         insert into euarticle (articleID,articleName,articleSubname,content,keywords, createtime)
         select articleID,articleName,articleSubname,content,keywords, createtime
         from article_test2 where categoryID = norID and ;

end
//


2. an example of case statement

select
CASE month when "01" then "January"
when "02" then "February"
when "03" then "March"
when "04" then "April"
when "05" then "May"
when "06" then "June"
when "07" then "July"
when "08" then "August"
when "09" then "September"
when "10" then "October"
when "11" then "November"
when "12" then "December"
END
from calendar where year = "2005" order by month;