当前位置: 代码迷 >> DB2 >> DB2 日期 方面有关问题
  详细解决方案

DB2 日期 方面有关问题

热度:3537   发布时间:2013-02-26 00:00:00.0
DB2 日期 方面问题

  字段 id getdate
  类型 varchar(10) date
  值1 1 2003-05-01
  

select 结果 from test where id='1'

我要的结果 是 getdate字段上一季度末的时间

如果 2003-05-01 的上一季度是 2003-03-31

可能出现这种情况

如果 2003-01-18 的 上季度是 2002-12-31

该 怎么写 求高手帮忙



------解决方案--------------------------------------------------------
楼主没说清楚返回类型是什么 我写了个字符串的 
select case when month(getdate) <= 3 then trim(char(year(getdate -1 years)))||'-12-31'
when month(getdate) <= 6 then trim(char(year(getdate)))||'-03-31'
when month(getdate) <= 9 then trim(char(year(getdate)))||'-06-30'
else trim(char(year(getdate)))||'-09-30' end
from test 

另外最好说明db2版本,我用的DB2 v9.5.0.7 ,
上面的语句执行通过,有时候某些新版的函数在老版本不能用
  相关解决方案