mysql - How to write if else condition in sql -


in following sql, how can add if-else control structure.

select         tblcabbooking.id id,         concat(tblcabstatus.`status`,' ',         ifnull(concat("(inr",tblbookingcharges.totalbill,")"),'')) `status`,          tblcomplaint.id com_id,         tblcomplaint.statusid com_status,         tblcabbooking.csr_id emp,         concat(tblcabbooking.dropaddress,tblcabbooking.droparea) drop_area,         tblbookingcharges.totalbill,          tblcabbooking.booking_reference ref,         tblmasterpackage.master_package booking_type,         concat(tblcabbooking.pickupdate," ",tblcabbooking.pickuptime) ordertime,         concat(tblclient.clientname," ",tblappid.`type`) partner,         concat(tblcablistmgmt.name,', ',tbldriver.firstname,"(",tbldriver.contactno,")") vehicle,          concat(tbluserinfo.firstname,"(",tbluserinfo.mobno,")") clientname,          concat(tbldriver.firstname," ",tbldriver.contactno) driver_name,         tblcabbooking.mobileno mob_no,         tbluserinfo.uid client_id,         tbldriver.uid driver_id,         concat(tblcabbooking.pickupaddress,' ',tblcabbooking.pickuparea) departure,         tbldriver.vehicleregistrationno reg          tblcabbooking      join      tblcabstatus      on        tblcabbooking.`status`=tblcabstatus.`status_id`      join      tbluserinfo      on        tbluserinfo.uid=tblcabbooking.clientid      join      tblmasterpackage      on        tblcabbooking.bookingtype=tblmasterpackage.package_id      left join tbldriver      on        tblcabbooking.pickup=tbldriver.uid      left join tblcablistmgmt      on        tbldriver.typeofvehicle=tblcablistmgmt.id      join      tblappid      on        tblappid.id=tblcabbooking.partner      join      tblclient      on        tblappid.clientid=tblclient.id      left join tblbookingcharges      on        tblcabbooking.id=tblbookingcharges.bookingid      left join tblcomplaint      on        tblcabbooking.id=tblcomplaint.bookingid          tblcabbooking.bookingdate >= fromdate      ,       tblcabbooking.bookingdate <= todate      ,       tblcabbooking.mobileno=ifnull(callerid,tblcabbooking.mobileno)      ,       tblcabbooking.booking_reference=ifnull(book_ref, tblcabbooking.booking_reference)      ,       tbldriver.vehicleregistrationno=ifnull(vehicle_number, tbldriver.vehicleregistrationno)     ,       tbldriver.firstname=ifnull(vehicle_driver, tbldriver.firstname)if partnertype 'android booking'     ,      tblcabbooking.devicetype='android'      else      if partnertype 'web booking'      ,      tblcabbooking.devicetype='web'      else      if partnertype 'call center booking'      ,      tblcabbooking.devicetype='0'      else      ,      partnertype=tblcabbooking.devicetype      end      if order tblcabbooking.id desc ; 

no, can't use if .. else construct in normal ansi sql query, can rewrite using case statement like

where tblcabbooking.devicetype =                  case when partnertype 'android booking'                  'android' else 'web booking' 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -