1

I am trying to execute the following query:

SELECT *
FROM OPENQUERY
(
    CLP,
    '
        SELECT *
        FROM ORACLE_TABLE
        WHERE [UPDATEDATE] > ''1900-01-01 12:00 AM''
    '
)

This query works fine when I remove the date criteria. But as soon as I try to pass this criteria it no longer works. I can't figure out what I am missing.

2 Answers 2

1

Try to remove [and] and add convert date:

SELECT * 
FROM OPENQUERY
(CLP, 
      '
         SELECT * 
         FROM ORACLE_TABLE 
         WHERE 
         UPDATEDATE > to_date(''1900-01-01 12:00'',''yyyy-mm-dd hh:mi'')
       '
)

or with am

SELECT * 
FROM OPENQUERY
(CLP, 
      '
         SELECT * 
         FROM ORACLE_TABLE 
         WHERE 
         UPDATEDATE > to_date(''1900-01-01 12:00 AM'',''yyyy-mm-dd hh:miam '')
       '
)
Sign up to request clarification or add additional context in comments.

9 Comments

Well, how do you think this would work if the UPDATEDATE column is of DATE datatype (which probably is the case)? it would probably be OK if the column is varchar2.
Run select to_date(sysdate,'yyyy-mm-dd hh:miam') from dual; and check for yourself. It will entirely depend on the NLS date parameter you have!
TO_CHAR would make more sense than TO_DATE. Like select to_char(sysdate,'yyyy-mm-dd hh:mi am') from dual;.
I tried this and I am getting the following error: "ORA-01830: date format picture ends before converting entire input string".
@Parado so you see spinon's edit... TO_DATE around a varchar makes more sense i.e. '1900-01-01 12:00' is a character string (varchar) field.
|
0

Use

SELECT *
FROM OPENQUERY
(CLP,SELECT * FROM ORACLE_TABLE WHERE trunc(UPDATEDATE) > ''01-JAN-1900'')

All dates with no time component on them defaults to 12:00 AM (or 00:00 Hrs) in Oracle.

You can also use to_timestamp(UPDATEDATE) but for this to work the column should be of timestamp type (i.e. contain timestamp on it otherwise it would always give 12 AM). You can also use to_char(UPDATEDATE,'YYYY-MM-DD HH:MI AM').

2 Comments

This did work but I do need the date and time to be compared as I am trying to find records that were updated after a certain date and time.
Yeah it isn't a timestamp but just a regular date field. The to_date function worked out so long as it was around the right information. Thanks for your help though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.