Skip to Content
avatar image
Former Member

Reserved Words"INTERVAL" in SAP HANA SQL

Hi,

The query counts the number of orders ordered in a given quarter of a given year in which at least one lineitem was received by the customer later than its committed date. And i used 'interval' to get the quarter.But the query can not be executed.How can I fix this problem?

select

  o_orderpriority,

  count(*) as order_count

from

  orders

where

  o_orderdate >= date '1993-07-01'

  and o_orderdate < date '1993-07-01' + interval '3' month

  and exists (

  select

  *

  from

  lineitem

  where

  l_orderkey = o_orderkey

  and l_commitdate < l_receiptdate

  )

Thanks in advance.

Naomy

error.PNG (15.7 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jan 08, 2015 at 01:31 PM

    Hello Naomy,

    I am not familiar with this kind of syntax and would usually either explicitly specify the ranges or use a function like ADD_DAYS:

      o_orderdate between to_date('1993-07-01', 'yyyy-mm-dd')

      and to_date('1993-09-30, 'yyyy-mm-dd')

      o_orderdate between to_date('1993-07-01', 'yyyy-mm-dd')

      and add_days(to_date('1993-07-01', 'yyyy-mm-dd'), 91)

    Alternatively you can use the QUARTER function, see QUARTER - SAP HANA SQL and System Views Reference - SAP Library.

    Kind regards

    Martin

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank you very much,Martin.😊

      I specified the ranges and use the ADD_DAYS function, and it work.