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()'
)