xml string as file

kasim mohamed 581 Reputation points


I have Nvarchar(max) column where xml string has been stored.
i wants to download that xml string as file. how to write the query for that?


SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,853 questions
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,560 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Olaf Helper 41,006 Reputation points
    0 comments No comments

  2. Bert Zhou-msft 3,421 Reputation points

    Hi,@kasim mohamed

    Welcome to Microsoft T-SQL Q&A Forum!

    As experts say, you can use sqlcmd Mode. It allows to output result of a query to a local file system.

    Please check this:

    -- switch to SQLCMD Mode   
    :out e:\Temp\outputFileName.xml  
    SELECT  [CurrencyCode] ,[Name]  ,[ModifiedDate]  
    FROM [AdventureWorks].[Sales].[Currency]  
    FOR XML PATH('row'), TYPE, ROOT('root');  

    Here is a detailed article about sqlcmd, you can refer to it.

    Best regards,
    Bert Zhou

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments