Skip to Content

logic into IQ

Please help me in converting the below logic into Sybase IQ. Below is from oracle.

NEXT_DAY(a.date_data - 366, TO_CHAR(a.date_data,'DAY'))

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Feb 24, 2014 at 08:06 PM

    IQ doesn't have a function corresponding to next_day() so you should write that yourself. It returns the first weekday of the specified type (e.g. a Monday, a Tuesday, or whatever the TO_CHAR() expression evaluates to) which is greater than the date resulting from ( a.data_data - 366), i.e. 366 days back in time.

    For the other bits:

    - a.data_data - 366 can be implemented in IQ as: DATEADD(day, -366, a.date_data)

    - TO_CHAR(a.date_data,'DAY')) can be implemented in IQ as DAYNAME(a.date_data)


    Rob V.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 25, 2014 at 03:54 PM


    IQ allows simple date math around whole dates. You could easily implement the Oracle logic like this:

    --- NEXT_DAY(a.date_data - 366, TO_CHAR(a.date_data,'DAY'))

    -- add the +1 to get the "next day"

    -- use DAYNAME() to return the text based day of week name: sunday, monday, etc

    DAYNAME ( a.date_data - 366 + 1 )


    Add comment
    10|10000 characters needed characters exceeded

    • Just to add: NEXT_DAY() in Oracle doesn't just give you the next day (as in: day+1).

      When you specify NEXT_DAY(some-date, 'monday'), it'll return the date of the first Monday following 'some-date'. I think there is no direct equivalent available in IQ for this which is why it would need to be written custom.

      Now, I just realized I actually have such a SQL function available - if someone wants it, please contact me ( Earlier comments about possible performance penalties for SQL functions in IQ apply.