• I think this will get you what you need:

    DECLARE @Result varchar(1000);

    WITH x(xx) AS (select * from Xml_Export listing for xml auto ,elements ,ROOT('Listings'))

    SELECT @Result='<?xml version="1.0" encoding="UTF-8" ?>'+xx

    FROM x

    --this will include the ?xml declaration

    --if you are exporting to an xml file then don't change it to xml

    SELECT @Result

    --This will strip the declaration

    SELECT CAST(@Result AS xml)

    I included two select statements in my example code to demonstrate how, when you cast as xml, the xml declaration is stripped out. For export you should declare @Result as varchar.

    Edit: Added comments to my code.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001