xml string as file

kasim mohamed 581 Reputation points
2022-03-15T08:06:50.837+00:00

Hi,

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?

Thanks

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

2 answers

Sort by: Most helpful
  1. Olaf Helper 43,331 Reputation points
    2022-03-15T09:06:55.32+00:00
    0 comments No comments

  2. Bert Zhou-msft 3,421 Reputation points
    2022-03-15T09:22:58.433+00:00

    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  
    SET NOCOUNT ON;  
    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