Home Forums SQL Server 2008 T-SQL (SS2K8) OPENQUERY error: An unexpected NULL value was returned RE: OPENQUERY error: An unexpected NULL value was returned

  • DataDeveloper (8/28/2014)


    I had the same issue pulling data into SQL Server from an AS400 server using OPENQUERY via a linked server. Try the following Syntax... it solved my problem. My issue involved date fields hence the date string. The key is using the NULLIF AS400 function in the OPENQUERY SQL.

    SELECT NULL_COLUMN AS ALIAS_NAME

    FROM OPENQUERY([LINKED_SERVER_NAME],'SELECT NULLIF(NULL_COLUMN,''0001-01-01'') AS NULL_COLUMN

    FROM CATALOG.LIBRARY.TABLE');

    <Face palm><Multiple head-desk> BWAAA-HAAA!!! Sometimes the simplest solutions are overlooked. Thanks, double D!

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)