5
Answers

Case statement Else part Not Working Properly .

Karthik K

Karthik K

1d
74
1

Hi ,  

            we had requirement to write the query up to Price change automatically based on the Start time and End Time .Mysql 

I have written query but its else part not get called .

we have Price like Price ,Price2,Price3,Price4 

 select
  case
  when S.SwitchPrice ='Price2'  then  I.Price2
  when S.SwitchPrice ='Price3'  then  I.Price3
  when S.SwitchPrice ='Price4'  then  I.Price4
  else I.Price
  end  AS Price
  FROM da5.SwitchPrice  as S inner join da5.Inventory as I on S.Inventoryid=I.Inventoryid
  where (TIME( CONVERT_TZ(NOW(), @@session.time_zone, '+8:00')) >  TIME(S.Start_Tm)
  AND  TIME( CONVERT_TZ(NOW(), @@session.time_zone, '+8:00')) <  TIME(S.End_Tm)) ;

the above query i tried but working partially . if the time  condition fails ..its show empty .rather than its point default Price .

Can any one help on this.

Thanks in advance ,

Karthik.K

 

 

 

Answers (5)