• Skuldouggery (1/13/2014)


    Hi,

    I ran this query multiple times last week in my SQL Server 2005 database and it worked fine. Today, I go to run the exact same query and it only returns the first row (code = 30001). I've tried other values of the BETWEEN statement and still the same behavior is evident. It's almost like the BETWEEN or the following AND is not working. This is driving me nuts. Would someone be kind enough to help me please? I restarted the database and rebooted the server too!!

    SELECT(

    SELECT ROW_NUMBER() OVER(ORDER BY DEM_EXTERNALID) AS '@id', DEM_EXTERNALID, IMREDEM_CODE, DEM_LASTNAME, DEM_FIRSTNAME, DEM_DATEOFBIRTH,IMREDEMEC_CODE,CHAT_DATE,NOTE_TEXT

    FROM HPSITE.DEMOGRAPHICS

    INNER JOIN HPSITE.CHARTATTACHMENT ON HPSITE.DEMOGRAPHICS.IMREDEM_CODE = HPSITE.CHARTATTACHMENT.IMREDEMEC_CODE

    INNER JOIN HPSITE.NOTES_MASTER ON HPSITE.CHARTATTACHMENT.IMRENOTE_CODE = HPSITE.NOTES_MASTER.IMRENOTE_CODE

    INNER JOIN HPSITE.NOTES_TEXTDATA ON HPSITE.NOTES_MASTER.IMRENOTE_CODE = HPSITE.NOTES_TEXTDATA.IMRENOTE_CODE

    WHERE IMREDEMEC_CODE BETWEEN '30001' AND '32000'

    AND DEM_LASTNAME <>'Demonstration'

    AND DEM_LASTNAME <>'Test'

    AND DEM_LASTNAME <>'Train'

    AND DEM_LASTNAME <>'Erroneous'

    FOR XML PATH('Row'), ROOT('Results'), ELEMENTS XSINIL

    ) AS COL_XML;

    Without table definitions and some data we can't even take a shot in the dark.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/