How to send xml to file

Posted on 2011-10-23
Last Modified: 2013-12-25
I have the following script that works great.  How can I write the results (select MyXML) to a file?

declare @myXml xml
SELECT @claimXML = (
SELECT     SourceDocumentTypeActionCode as  '@ActionCode',
            Status as '@Status',
            RecipientName as '@RecipientName',
            ClaimPayeeType '@ClaimPayeeType',
                  '' as 'Participant/@FirstName',
                  '' as  'Participant/@LastName',
                  SSN as 'Participant/@SSN',
                         ProviderName as 'Provider/@ProviderName',
                              AddressLine1 as 'Provider/MailingAddress/@AddressLine1',
                             AddressLine2 as 'Provider/MailingAddress/@AddressLine2',
                              City as 'Provider/MailingAddress/@City',
                              StateCode as 'Provider/MailingAddress/@StateCode',
                              ZipCode as 'Provider/MailingAddress/@ZipCode',
                              'US'as 'Provider/MailingAddress/@CountryCode',
                                    ExternalClaimNumber  as 'ClaimDetail/@ExternalClaimNumber',
                                    ClaimAmount  as 'ClaimDetail/@ClaimAmount',
                                    'true' as 'ClaimDetail/@ReceiptReceived',
                                    'false' as 'ClaimDetail/@ClaimOnHold',
                                    ExpenseCategory as 'ClaimDetail/@ExpenseCategory',
                                    ExpenseType as 'ClaimDetail/@ExpenseType',
                                    case when ClaimPayeeType ='PTP' then 'Provider Payment'
                                          when ClaimType =''then KeyName
                                          end as 'CustomProperties/@KeyName',
                                          case when ClaimPayeeType ='PTP' then KeyValue
                                          when ClaimType =''then KeyValue
                                          end as 'CustomProperties/@KeyValue'      

FROM        My_Table


--Start of XML File Header  
      DEFAULT 'http://www.TheUsual/2008/10/01/',
      '' as "xsi",
      '' as "xsd")

SELECT @myXml = (

      'Administrator' AS '@AdminAlias',
      COUNT(ExternalClaimNumber) AS '@TotalClaimsCount',
      getdate() as '@CreatedDateTime',
FROM         MY_Table

FOR XML PATH('StandardExchange'))

select @myXml
Question by:kat50
    1 Comment
    LVL 25

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    Read about achieving the basic levels of HRIS security in the workplace.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now