公司給我一個需求
要計算 假別的是使用率
公式 : 已休時數/(上期時數+公司給假)
計算公式 (EMPLOYEE_SPECIAL_TRAN_MAX + SPECIAL_REMAIN_HOURS-(EMPLOYEE_SPECIAL_TRAN + SPECIAL_REMAIN_HOURS)---->欄位名 已休時數(TOTAL_HOUR)
計算公式 (EMPLOYEE_SPECIAL_TRAN_MAX+EMPLOYEE_SPECIAL_VALUE) --->上期結轉+公司給假
欄位名 特休已使用率(USE_PERCENT)
SQL 下的語法
(CASE WHEN (EMPLOYEE_SPECIAL_TRAN_MAX + SPECIAL_REMAIN_HOURS-(EMPLOYEE_SPECIAL_TRAN + SPECIAL_REMAIN_HOURS))> 0 AND (EMPLOYEE_SPECIAL_TRAN_MAX+EMPLOYEE_SPECIAL_VALUE) < 0 AND (EMPLOYEE_SPECIAL_TRAN_MAX + SPECIAL_REMAIN_HOURS) = 0 THEN 0
WHEN (EMPLOYEE_SPECIAL_TRAN_MAX + SPECIAL_REMAIN_HOURS-(EMPLOYEE_SPECIAL_TRAN + SPECIAL_REMAIN_HOURS)) > 0
THEN ((EMPLOYEE_SPECIAL_TRAN_MAX + SPECIAL_REMAIN_HOURS-(EMPLOYEE_SPECIAL_TRAN + SPECIAL_REMAIN_HOURS))/(EMPLOYEE_SPECIAL_TRAN_MAX+EMPLOYEE_SPECIAL_VALUE))ELSE 0 END) AS USE_PERCENT
出現的資料,會因為 有未到職一年的同仁 上期結轉為0 公司給假24 特休使用率出來應該是0
但 SQL SERVER 出現 0E-18
要如何解決 0E-18 而從資料庫呈現 為0 呢 ?
修改後的SQL如下:
SELECT ITEM, SALES, CONTACT, DUE_DATE
FROM AVM_AVI.IT_YEARLY_REMINDER
WHERE TO_CHAR(TO_DATE(DUE_DATE, 'yyyy/mm/dd') - 60, 'yyyymmdd') <= to_char(SYSDATE, 'yyyymmdd')
AND TO_CHAR(TO_DATE(DUE_DATE, 'yyyy/mm/dd'), 'yyyymmdd') > to_char(SYSDATE, 'yyyymmdd')
AND (ROUND(TONUMBER(TO_DATE(DUE_DATE, 'yyyyMMdd') - sysdate)) = 60 OR MOD(ROUND(TO_NUMBER(TO_DATE(DUE_DATE, 'yyyyMMdd') - sysdate)), 7) = 0)
AND TYPE = '合約';