0

When I run this SQL in SSMS (all versions 2005-2014) the final select statement's Child column has data that is missing the final CHAR(13) and CHAR(10). Is there a way to have OPENXML or it's WITH clause specify not to truncate these characters?

DECLARE @IDoc INT
DECLARE @SerializedEntity XML

CREATE TABLE #BadResultTable(doc XML)

INSERT INTO #BadResultTable(doc)
    SELECT NewXML=
     (SELECT Child='Please dont strip my carriage return' + CHAR(13) + CHAR(10)
      FOR XML PATH('Parent'), TYPE, ELEMENTS XSINIL)

SET @SerializedEntity = (SELECT doc FROM #BadResultTable FOR XML PATH('Parent'), TYPE, ELEMENTS XSINIL)

EXEC sp_xml_preparedocument @IDoc OUTPUT, @SerializedEntity

/*PROBLEM HERE: The Child column is missing the training CHAR(13) and CHAR(10)*/
SELECT Child,ASCII(SUBSTRING(Child, LEN(Child), 1))
        FROM OPENXML(@IDoc, '/Parent', 2)
        WITH (Child NVARCHAR(MAX) '//Child/text()'
    )
4

1 回答 1

1

I don't see a way to get OPENXML to do that.

Why not just use XQuery since you've already got the data in an XML column? The CR+LF are present in the XML column. It's only OPENXML that destroys them.

于 2014-12-19T21:23:34.813 回答