openquery worked in SQL 2005 but not in 2008

  • I have a querythat works in SQL Server 2005, but has an error using it in SQL Server 2008.

    select * from openquery (LAWSONPROD,

    'SELECT

    COMPANY,

    JOB_CODE,

    DESCRIPTION,

    JOB_CLASS,

    ACTIVE_FLAG,

    CASE WHEN EFFECT_DATE < TO_DATE(''01-JAN-00'') THEN NULL ELSE TO_CHAR(EFFECT_DATE) END,

    TO_CHAR(CURRENT_DATE,''DD-MON-YYYY HH:MI'')

    FROM PROD.JOBCODE

    ORDER BY JOBCODE.JOB_CODE' )

    Any ideas why? Thanks very much.

  • I have answer to your question. You get the error because something is wrong!

    Don't you mind to tell us the error you getting?

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Denise McMillan (8/4/2011)


    I have a querythat works in SQL Server 2005, but has an error using it in SQL Server 2008.

    SELECT *

    FROM OPENQUERY(LAWSONPROD, 'SELECT

    COMPANY,

    JOB_CODE,

    DESCRIPTION,

    JOB_CLASS,

    ACTIVE_FLAG,

    CASE

    WHEN EFFECT_DATE < TO_DATE(''01-JAN-00'') THEN NULL

    ELSE TO_CHAR(EFFECT_DATE)

    END,

    TO_CHAR(CURRENT_DATE,''DD-MON-YYYY HH:MI'')

    FROM PROD.JOBCODE

    ORDER BY JOBCODE.JOB_CODE')

    Any ideas why? Thanks very much.

    I gather that LAWSONPROD links to an Oracle database given the use of TO_CHAR(). Assuming it's a new server hosting SQL 2008 did you install the Oracle drivers and configure TNSNAMES.ORA?

    PS I agree with Eugene. When asking for help to resolve an error, it's common courtesy to post the actual error message 🙂

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • I'm sorry, I forgot to put that in! Error is:

    OLE DB provider "OraOLEDB.Oracle" for linked server "LAWSONPROD" returned message "ORA-01858: a non-numeric character was found where a numeric was expected".

    Thanks again.

  • Denise McMillan (8/4/2011)


    I'm sorry, I forgot to put that in! Error is:

    OLE DB provider "OraOLEDB.Oracle" for linked server "LAWSONPROD" returned message "ORA-01858: a non-numeric character was found where a numeric was expected".

    Thanks again.

    It happens 🙂 Thanks for posting back.

    I guess this could be an OLEDB problem, however this seems to come straight from the Oracle engine. <throwing_mud>Have you run this query directly on the Oracle database? Just to rule out the query itself and isolate that it is in fact a SQL Server problem?</throwing_mud>

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • You get an Oracle error, it is nothing to do with SQL Server.

    Can you execute this query successfully in Oracle itself?

    Do you have up-to-date OracleOledb driver?

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Try expliciting the date format in TO_DATE / TO_CHAR.

    Maybe you installed the client with different locale settings and the dates don't get parsed/converted correctly.

    -- Gianluca Sartori

  • Yes, it is linked server to an Oracle database. And also yes, it's a new server with Oracle client and tnsnames in place. Thanks so much.

  • Here's what worked:

    select * from openquery (LAWSONPROD,

    'SELECT

    COMPANY,

    JOB_CODE,

    DESCRIPTION,

    JOB_CLASS,

    ACTIVE_FLAG,

    CASE WHEN EFFECT_DATE < TO_DATE(''01-JAN-00'', ''DD-MON-YY'') THEN NULL

    ELSE TO_CHAR(EFFECT_DATE) END as effectdate,

    TO_CHAR(CURRENT_DATE,''DD-MON-YYYY HH:MI AM'') as currdate

    FROM PROD.JOBCODE

    ORDER BY JOBCODE.JOB_CODE' )

    Thanks very much for all ideas.

  • Glad you sorted it out.

    -- Gianluca Sartori

  • Hi All,

    After spending hours I found it has to do with how "date" datatypes are handled in Oracle and MS SQL. Putting this function TO_DATE ('DD-MON-YYYY', 'DD-MON-RRRR') arpund all date datatypes in Oracle views have solved the problem. Replace DD-MON-RRRR with required date.

    Hope this will help.

  • Hi All,

    After spending hours I found it has to do with how "date" datatypes are handled in Oracle and MS SQL. Putting this function TO_DATE ('DD-MON-YYYY', 'DD-MON-RRRR') arpund all date datatypes in Oracle views have solved the problem. Replace DD-MON-RRRR with required date.

    Hope this will help.

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply