2 Replies Latest reply: Aug 7, 2013 7:14 PM by VictorFagundo RSS

    TimeStampDiff function ROUNDing the result. How can we avoid this?

    user6848968
      Hi,

      I am using the following timestamp function:
      TIMESTAMPDIFF(SQL_TSI_HOUR, "SF_CS_CS_Fact"."Crtddt_Dt", "SF_Emlmssg_Sum_CS"."Initl Resp Tm")

      I notice that the result set is rounded off to the whole no.

      This is happening because OBIEE autimatically ROUNDS the difference of the timestamps whe using TIMESTAMPDIFF:

      select distinct D1.c1 as c1,
      D1.c2 as c2,
      D1.c3 as c3,
      D1.c4 as c4,
      D1.c5 as c5,
      D1.c6 as c6,
      D1.c7 as c7,
      D1.c8 as c8,
      D1.c9 as c9,
      D1.c10 as c10
      from
      (select D1.c1 as c1,
      D1.c2 as c2,
      D1.c3 as c3,
      D1.c4 as c4,
      D1.c5 as c5,
      D1.c6 as c6,
      D1.c7 as c7,
      D1.c8 as c8,
      D1.c9 as c9,
      D1.c10 as c10
      from
      (select 0 as c1,
      D1.c4 as c2,
      D1.c5 as c3,
      D1.c3 as c4,
      D1.c2 as c5,
      D1.c6 as c6,
      D1.c7 as c7,
      D1.c8 as c8,
      D1.c9 as c9,
      D1.c1 as c10,
      ROW_NUMBER() OVER (PARTITION BY D1.c2, D1.c3, D1.c4, D1.c5, D1.c6, D1.c7, D1.c8, D1.c9 ORDER BY D1.c2 ASC, D1.c3 ASC, D1.c4 ASC, D1.c5 ASC, D1.c6 ASC, D1.c7 ASC, D1.c8 ASC, D1.c9 ASC) as c11
      from
      (select distinct ROUND ( ( CAST(T14421.INITIAL_RESPONSE_TIME as DATE)  - CAST(T14963.CRTDDT_DT as DATE)  ) 24 ) as c1*,
      T14963.CRTDDT_DT as c2,
      T14963.CSNMBR as c3,
      T4813.FISCAL_YEAR_NAME as c4,
      T4813.FISCAL_QUARTER_NAME as c5,
      T14421.INITIAL_RESPONSE_TIME as c6,
      T14468.GRP as c7,
      T4813.FISCAL_YEAR_ID as c8,
      T4813.FISCAL_QUARTER_ID as c9
      from
      DW_SF_EMLMSSG_SUM_CS T14421,
      DW_SF_EMLMSSG_CS T14400,
      SF_ORGN_CS_DIM T14468,
      CIN_CALENDARS_DIM T4813,
      DW_SF_CS_CS T14963 /* SF_CS_CS_Fact */
      where ( T14400.PRNTID = T14963.ID and T4813.CALENDAR_KEY = T14963.CRDT_KEY and T14421.PRNTID = T14963.ID and T14400.STTS = '3' and T14468.ORGN_KEY = T14963.ORGN_KEY and T14963.TYP = 'CIN' and (T14963.CSNMBR in ('1103676964', '1103677035', '1103677076', '1103677285', '1103677303', '1103677369', '1103677389')) )
      ) D1
      ) D1
      where ( D1.c11 = 1 )
      ) D1
      order by c1, c8, c9, c7, c4, c5, c6, c10

      Please see the line in Bold in the query.
      I want to get the results in the actual decimal point and not the whole no. Is there a way that I can enable the TIMESTAMPDIFF not to ROUND by default.
      Any answers will be helpful.

      Thanks,
        • 1. Re: TimeStampDiff function ROUNDing the result. How can we avoid this?
          Chadical

          Tested in 11G.

          1. Need to use minutes.

          2. It's all about casting the denominator.

          3. Also change the column format to show additional decimal places.

          TIMESTAMPDIFF(SQL_TSI_MINUTE, "SF_CS_CS_Fact"."Crtddt_Dt", "SF_Emlmssg_Sum_CS"."Initl Resp Tm") / cast( 60 as real )

          OR

          TIMESTAMPDIFF(SQL_TSI_MINUTE, "SF_CS_CS_Fact"."Crtddt_Dt", "SF_Emlmssg_Sum_CS"."Initl Resp Tm") / 60.000000000001

          (A bit hackish, but easier to tell users sometimes.)

          • 2. Re: TimeStampDiff function ROUNDing the result. How can we avoid this?
            VictorFagundo

            When you specify in the interval in the first argument of TIMESTAMPDIFF you are implicitly telling OBIEE the level of precision that you want. For SQL_TSI_YEAR you are going to get integer values of whole years. if yo uneed to get more granular than that you need to use SQL_TSI_MONTH or WEEK.

             

            Also note, than when performing mathematical operations like divide an multiply, all elements of the calculation need to be a data type that can represent decimal values, or the result of the entire calc will always get converted to an integer.