是这样,我这里有一个统计上报的功能,如果日期为空,那么为未报,如果有日期,则比较日期;6号前为按时上报,之后为延时上报;上报数据存储采用TIMESTAMP(6),比较时是采用查询日期条件to_date(2010||'-'||06||'-06', 'yyyy-MM-dd')
这里的数字是我替换掉变量写的
我想返回日期在6号后的,返回1,6号以前的返回2;可是只能返回1
我在表里看到有按时上报的数据,所以这里数据查询语句写的有点问题,请高手指点下
case when monthplan.created is null then 0
          when monthplan.created >= to_date(2010||'-'||06||'-06', 'yyyy-MM-dd') then 1
          else 2 end  as reportState

解决方案 »

  1.   

    你的报表统计应该是每个月的六号之前为按时上报吧,所以应该只比较月和日就可以了。
    例如: 2010-07-03的数据,应该是按时上报的,但是按你这个写出来,就是未按时上报了。
    我这里没有Oracle,所以没有写出SQL,就是只比较 MM-DD就可以了,很简单的不知道我理解的对不对,呵呵
      

  2.   

    哈哈,谢谢你,不过,系统都是写好的,我不能因为一个SQL语句去把现在的系统给改了,再说这是一个扩展功能,比如说:客户想查询2009年的数据,你说的就无法实现了
      

  3.   

    我修改了句子to_timestamp(2010||'-'||06||'-06', 'yyyy-MM-dd')由于上述功能是在一个跨表查询中实现的,我单独执行一个表的时候,可以实现我说的功能,但是到跨表里面就不可以了,有点晕了
      

  4.   

    照理说单表可以了,跨表应该也是没问题的啊,是不是关联条件有问题,或换成to_timestamp(to_date('','yyyy-mm-dd'))格式试试,不过结果应该是一样的
      

  5.   

    decode(created,'',0,decode(sign(to_char(created,'dd')-6),1,1,-1,2,0,1))
      

  6.   

    上报时间为每月25号到次月6号为按时上报,6号以后为迟报,25号以后为未报,
    举个例子:可是查询条件传进去的是2010-06,在SQL语句中又添加了06合成2010-06-06为上报日期to_date(:par_yearN||'-'||:par_monthN||'-25', 'yyyy-MM-dd')那么我要是调用5月25号到6月25号的数据,这个where条件该如何写呢?monthplan.reportdate >= to_date(:par_yearN||'-'||:par_monthN||'-25', 'yyyy-MM-dd') and monthplan.reportdate < to_date(:par_yearN||'-'||:par_monthN||'-25', 'yyyy-MM-dd')
      

  7.   

    下面是完整的查询语句select 
    'com.bjcx.emergency.report.actionform.SafetyMonthPlanDetailActionFormQuery_'||:par_yearN ||'_'||:par_monthN||'_'||:par_deptId||'_'||companyid as id
    ,companyid
    ,companyname
    ,companycode
    ,monthplanid
    ,decode(countx,0,reportState,3) reportState
    from (
    select comdisplay.companyname
    ,comdisplay.companycode
    ,comdisplay.companyid
    ,monthplan.monthplanid
    ,(select count(*)
           from bms_companyinfo cominfo
    where cominfo.parentid = comdisplay.companyid
          and cominfo.logyes = 1
          and cominfo.companytype in (0,2,4,6,8))   as countx
        ,case
       when
    monthplan.created is null then 0
    when monthplan.reportdate >= to_date(:par_yearN||'-'||:par_monthN||'-06', 'yyyy-MM-dd')
    and monthplan.reportdate < to_date(:par_yearN||'-'||:par_monthN||'-25', 'yyyy-MM-dd') then 1
    else 2 end  as reportState
    from view_company_sum comsum
    left join dms_safetymonthplan monthplan
    on comsum.compid = monthplan.deptid
    and monthplan.yearn = :par_yearN
    and monthplan.reportdate >= to_date(:par_yearN||'-'||(to_number(:par_monthN)-1)||'-25', 'yyyy-MM-dd')
    and monthplan.reportdate < to_date(:par_yearN||'-'||:par_monthN||'-25', 'yyyy-MM-dd')
    join view_company_display comdisplay
    on comsum.compid = comdisplay.companyid
    and comsum.compid = comdisplay.topid
    where comsum.topid = :par_deptId and comdisplay.companyid > 21
    ) src
    where reportState = :par_reportState
    order by companycode这个在PL/SQL中替换所有变量执行通过的,但是在jboss下报错,提示:建立会话异常,请高手指点下,这个正确的写法该是怎么样的?
      

  8.   

    改过了,把日期修改为between and条件就可以在jboss下运行了