How to Save Condition Case or IF to variabel in MySQL -
how save condition case or if variabel?
dont need write same condition again next.
this mysql syntax :
select v_jadwal_personal.id_karyawan, v_jadwal_personal.nik_karyawan, (case when (select wkt_masuk d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja) < 0 addtime(jam_masuk,(select wkt_plg d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja)) when (select wkt_masuk d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja) >= 0 addtime(jam_masuk,(select wkt_plg d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja)) end) jammasuk, (case when (select wkt_plg d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja) < 0 addtime(jam_pulang,(select wkt_plg d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja)) when (select wkt_plg d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja) >= 0 addtime(jam_pulang,(select wkt_plg d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja)) end) jampulang, v_jadwal_personal.totaljam, v_tmp_history_absensi.waktu_masuk, v_tmp_history_absensi.waktu_pulang, v_tmp_history_absensi.hari_kerja, v_tmp_history_absensi.tgl_kerja, v_tmp_history_absensi.nama_karyawan, timediff(waktu_pulang,waktu_masuk) totaljamkerja, (case when (select wkt_masuk d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja) < 0 timediff(waktu_masuk,(addtime(jam_masuk,(select wkt_plg d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja)))) when (select wkt_masuk d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja) >= 0 timediff(waktu_masuk,(addtime(jam_masuk,(select wkt_plg d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja)))) end) terlambat, timediff(jam_pulang,waktu_pulang) lebihan, (select wkt_masuk d_jamkerja_khusus tgl_krj between '2014-05-14' , '2014-05-23' , tgl_krj=v_tmp_history_absensi.tgl_kerja) teswaktu v_jadwal_personal join v_tmp_history_absensi on v_tmp_history_absensi.id_karyawan = v_jadwal_personal.id_karyawan , v_tmp_history_absensi.hari_kerja = v_jadwal_personal.nama_hari v_tmp_history_absensi.tgl_kerja between '2014-05-14' , '2014-05-23' , v_jadwal_personal.id_karyawan=1
so, think many case condition , thats have same condition..
you can use subquery 1 of tables:
select ... table join table on condition join ( select long_computation result table condition ) s on condition condition
then can use s.result.
an alternative use view, that's valid if bit factorise same.
Comments
Post a Comment