• You can store it in a table or a variable and work with it ok. It just depends what you need to do with the XML.. Once you have shredded the XML, do you need it anymore? if not then storing it in a variable will be just fine..

    Here is a way to get the XML from file into a variable to work with it:

    DECLARE @xml XML

    SELECT @xml = (SELECT * FROM OPENROWSET(BULK 'c:\Temp\SomeXmlFile.Xml', SINGLE_BLOB) x)

    The filepath does need to be relative to the SQL server and the account that the SQL server service runs under will need to have permissions to access the file. If you are running SQL server under the localsystem account, then I don't believe it will be able to access the file over the network.

    Once you have it in a variable, then you can use the XML methods to begin to shred it. The most simplest one is value(). Another good one which helps with shredding XML to a table is nodes(). There are loads of blog posts on shredding XML to a table using nodes(). I've done a couple myself 🙂

    Here is a simple example using the value() method:

    SELECT @xml.value('(/Cfo/Env/text())[1]', 'varchar(20)')