• Alan.B,

    I think you missing the point.

    The question was not about use of XML in real life, but about why we cannot store XML files using good old nvarchar/ntext data type.

    Your example does not show any use of XML data processing.

    Yes, the outcome is an XML file, but you totally operate with varchar values.

    You could read, parse, build XML files in SQL Server 2000, having no XML data in place.

    Out of curiosity I put your script into Query Analyzer and after minor syntax tweaks it worked fine in SQL 2000:

    IF OBJECT_ID('tempdb..#testdata') IS NOT NULL

    DROP TABLE #testdata

    CREATE TABLE #testdata (id int primary key, txt varchar(100) NOT NULL)

    INSERT INTO #testdata

    SELECT 1,'Paragraph 1...' UNION ALL

    SELECT 2,'Paragraph 2...' UNION ALL

    SELECT 3,'Paragraph 3...'

    GO

    DECLARE @pars AS varchar(1000),

    @wordDoc varchar(1000)

    SET @pars=''

    SET @wordDoc ='<!--?-->

    <w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">

    <w:body><!--x--></w:body>

    </w:wordDocument>'

    SELECT @pars=@pars+d+CHAR(13)

    FROM (

    SELECT '<w:p><w:r><w:t>'+CAST(id AS char(1))+': '+txt+'</w:t></w:r></w:p>'+CHAR(13)

    FROM #testdata) data(d)

    SELECT REPLACE(REPLACE( @wordDoc,'<!--?-->',

    '<?xml version="1.0" encoding="ISO-8859-1"?>'+CHAR(13)+

    '<?mso-application progid="Word.Document"?>'),

    '<!--x-->',CHAR(13)+@pars)

    You see? You do not need XML data type for this at all.

    _____________
    Code for TallyGenerator