先日、こちらでSQL文の書き方について質問をさせていただきました。
Java
1 Date date = new Date(); 2 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); 3 String yyyymm ; 4 int yyyy = Integer.parseInt(sdf.format(date).substring(0,4)); 5 int mm = Integer.parseInt(sdf.format(date).substring(4,6)); 6 int dd = Integer.parseInt(sdf.format(date).substring(6,8)); 7 String kijun ; //検索基準日 8 9 if(dd <= 15){ //1~15日の場合、検索日付を同年同月16日 10 yyyymm = Integer.toString(yyyy) + Integer.toString(mm); 11 kijun = yyyymm + "16"; 12 }else{ 13 if(mm == 12){ //12月16~31日の場合、検索日付を翌年1月1日 14 yyyymm = yyyy+1 + "01"; 15 }else if(mm+1 < 10){ //1月~8月の16~31日の場合、同年翌月1日 16 yyyymm = yyyy + "0" + Integer.toString(mm+1); 17 }else{ 18 yyyymm = yyyy + Integer.toString(mm+1); 19 } 20 kijun = yyyymm + "01"; 21 } 22 23 try { 24 strSql = "SELECT " + crLf; 25 strSql += " MC.seq " + crLf; 26 strSql += ",MC.years_months " + crLf; 27 strSql += ",dates " + crLf; 28 strSql += "FROM " + crLf; 29 strSql += " mst_calendar MC" + crLf; 30 strSql += "WHERE " + crLf; 31 strSql += " MC.flg = '1' " + crLf; 32 strSql += " AND " + crLf; 33 strSql += " CONCAT(years_months + dates) > CONVERT(112, CURRENT_DATE) " + crLf; 34 strSql += " ORDER BY years_months ASC, dates ASC " + crLf; 35 strSql += " OFFSET 4 FETCH 1";
上記のような処理にしたのですが、
処理で「kijun」としている日付を使用したSELECT文にしたいと考えています。
条件のところの「CONVERT(112, CURRENT_DATE)」を変数「kijun」にすることは可能でしょうか。