Skip to Main Content

Analytics Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Filter date column (First Date of Last Month -30 d) AND (Last Date - 30 d)

972270Nov 2 2012 — edited Nov 4 2012
I have a query i need to run every month in our version of Analytics (Answers?) for Siebel 8.1.1 that reports the entries in the database with a reported date that is no earlier than 30 days before the first date of last month, and no later than 30 days before the last date of last month.

I found the following SQL formulas to calculate the first and last dates:

First Day of the Previous Month
TIMESTAMPADD(SQL_TSI_MONTH, -1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) -(1) + 1, CURRENT_DATE))*

From right to left the first TIMESTAMPADD returns the first day of the Current Month. The second TIMESTAMPADD then subtracts one month from the first day of the Current Month arriving to the First Day of the previous month.

Last Day of the Previous Month
TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) -(1) + 1, CURRENT_DATE))*

From right to left the first TIMESTAMPADD returns the first day of the Current Month. The second TIMESTAMPADD subtracts a month to arrive at the first day of the previous

My filters (converted to SQL) then read:

*"Service Request"."Reported Date" >= (TIMESTAMPADD(SQL_TSI_MONTH, -1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) -30)*
*"Service Request"."Reported Date" <= (TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) -30)*

Each one gives me a valid data set result, but when both are entered as and AND query....I get

+State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 59001] Subtract operation is not permitted on TIMESTAMP, INTEGER operand(s). (HY000)+


Any help in either fixing my understanding of the way to get this data, or in my managing of SQL language or design?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details