專案中用到的sql語句(case when...then... end )
阿新 • • 發佈:2019-02-07
String sql = "select t.ID,t.ORDER_NO,t.TASK_ID,t.TASK_NAME, "
+ "t.TASK_START_TIME,t.TASK_END_TIME,t.USED_TIME, "
+ "t.PROCESS_INSTANCE_ID,t.CREATE_USER,t.CREATE_USER_NAME, "
+ "t.CREATE_DEPT_ID,t.CREATE_DEPT_NAME,t.CREATE_TIME,t.END_TIME,t.ORDER_TOTAL_DURATION, "
+ "t.EVENT_TITLE, "
+ "(case when t.END_TIME is null then '未歸檔' else '已歸檔' end) as ORDER_STATUS, "
+ "t.EVENT_TYPE, "
+ "(select a.TYPE_NAME from MON_ALARM_TYPE a where a.ID=t.EVENT_TYPE)as EVENT_TYPE_NAME, "
+ "t.ORDER_LEVEL,( "
+ "select TYPENAME from ISDP_T_S_TYPE c ,ISDP_T_S_TYPEGROUP d "
+ "where d.TYPEGROUPCODE='ORDER_EVENT_LEVEL' "
+ "and c.TYPEGROUPID = d.ID "
+ "and c.TYPECODE = t.ORDER_LEVEL "
+ ") as ORDER_LEVEL_NAME,t.IF_CHANGE_CONFIG, "
+ "( case when t.IF_CHANGE_CONFIG = '1' then '是' else '否' end) as IF_CHANGE_CONFIG_NAME,t.TASK_FORM_KEY "
+ buildCondSql(map);
+ "t.TASK_START_TIME,t.TASK_END_TIME,t.USED_TIME, "
+ "t.PROCESS_INSTANCE_ID,t.CREATE_USER,t.CREATE_USER_NAME, "
+ "t.CREATE_DEPT_ID,t.CREATE_DEPT_NAME,t.CREATE_TIME,t.END_TIME,t.ORDER_TOTAL_DURATION, "
+ "t.EVENT_TITLE, "
+ "(case when t.END_TIME is null then '未歸檔' else '已歸檔' end) as ORDER_STATUS, "
+ "t.EVENT_TYPE, "
+ "(select a.TYPE_NAME from MON_ALARM_TYPE a where a.ID=t.EVENT_TYPE)as EVENT_TYPE_NAME, "
+ "t.ORDER_LEVEL,( "
+ "select TYPENAME from ISDP_T_S_TYPE c ,ISDP_T_S_TYPEGROUP d "
+ "where d.TYPEGROUPCODE='ORDER_EVENT_LEVEL' "
+ "and c.TYPEGROUPID = d.ID "
+ "and c.TYPECODE = t.ORDER_LEVEL "
+ ") as ORDER_LEVEL_NAME,t.IF_CHANGE_CONFIG, "
+ "( case when t.IF_CHANGE_CONFIG = '1' then '是' else '否' end) as IF_CHANGE_CONFIG_NAME,t.TASK_FORM_KEY "
+ buildCondSql(map);
return sql;
case when ** then *** end 用法 何時用
通過上面後臺的查詢, 將資料在頁面上顯示出來
<td class="searchTable_right" align="left"><select
id="IF_CHANGE_CONFIG" name="IF_CHANGE_CONFIG" style="width: 90px">
<option value="" selected>-請選擇-</option>
<option value="1">是</option>
<option value="0">否</option>
</select></td>