Exporting data that is stored as XML data type to XML file

  • Hi,

    I have a table containing rows of XML data stored in the SQL XML Data type. I'd like to export the complete XML in each row to one concatenated XML file, then add some final body tags around the lot - is this possible using T-SQL?

    I have used bcp to successfully do this for one row to one XML file, but when trying multiple rows to one XML file the charcters aren't readable. This is what I have used so far:

    declare @cmd nvarchar(255);

    select @cmd = '

    bcp "SELECT TOP 10 XMLColumn from DB1.[dbo].[XMLFiles] " ' +

    'queryout "C:\sample.xml" -S myserver -T -w -r -t';

    exec xp_cmdshell @cmd;

    go

    Can anyone help?

  • Like this?

    declare @cmd nvarchar(255);

    select @cmd = '

    bcp "select cast(cast(XMLColumn as nvarchar(max)) as xml) from DB1.[dbo].[XMLFiles] for xml path('')" ' +

    'queryout "C:\sample.xml" -S myserver -T -w -r -t';

    exec xp_cmdshell @cmd;

    go



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply