Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Export Table to Xml Using Sql

Export Table to Xml Using Sql

Scheduled Pinned Locked Moved Database
databasesql-serversysadminxmlquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nagaraju_Focus
    wrote on last edited by
    #1

    Hi All, Is there any Query to Export Table to Xml File Using Sql Server? Plz Suggest Me ... Thx in Advance Nagaraju

    M 1 Reply Last reply
    0
    • N Nagaraju_Focus

      Hi All, Is there any Query to Export Table to Xml File Using Sql Server? Plz Suggest Me ... Thx in Advance Nagaraju

      M Offline
      M Offline
      Maharishi Bhatia
      wrote on last edited by
      #2

      In MS SQL Server 2000 there is a "FOR" clause which you can use to retrive the select query result in xml. Basic syntax is as follows, FOR XML mode [, XMLDATA] [, ELEMENTS][, BINARY BASE64] Arguments XML mode Specifies the XML mode. XML mode determines the shape of the resulting XML. mode can be RAW, AUTO, or EXPLICIT. XMLDATA Specifies that an XML-Data schema should be returned. The schema is prepended to the document as an inline schema. ELEMENTS If the ELEMENTS option is specified, the columns are returned as subelements. Otherwise, they are mapped to XML attributes. This option is supported in AUTO mode only. BINARY BASE64 If the BINARY Base64 option is specified, any binary data returned by the query is represented in base64-encoded format. To retrieve binary data using RAW and EXPLICIT mode, this option must be specified. In AUTO mode, binary data is returned as a reference by default. Example : Select * from TableName for xml auto You can search the SQL transact help for further details.

      Nothing is Impossible. Even impossible spells "i m possible"

      N 1 Reply Last reply
      0
      • M Maharishi Bhatia

        In MS SQL Server 2000 there is a "FOR" clause which you can use to retrive the select query result in xml. Basic syntax is as follows, FOR XML mode [, XMLDATA] [, ELEMENTS][, BINARY BASE64] Arguments XML mode Specifies the XML mode. XML mode determines the shape of the resulting XML. mode can be RAW, AUTO, or EXPLICIT. XMLDATA Specifies that an XML-Data schema should be returned. The schema is prepended to the document as an inline schema. ELEMENTS If the ELEMENTS option is specified, the columns are returned as subelements. Otherwise, they are mapped to XML attributes. This option is supported in AUTO mode only. BINARY BASE64 If the BINARY Base64 option is specified, any binary data returned by the query is represented in base64-encoded format. To retrieve binary data using RAW and EXPLICIT mode, this option must be specified. In AUTO mode, binary data is returned as a reference by default. Example : Select * from TableName for xml auto You can search the SQL transact help for further details.

        Nothing is Impossible. Even impossible spells "i m possible"

        N Offline
        N Offline
        Nagaraju_Focus
        wrote on last edited by
        #3

        Thanks Maharishi, But I need to Save the whole table Data into a xml file which is to be created with a sql query. means Select * from TableName to "c:\test.xml" I need a query to send whole sql table to cml file is there any way to do like that? thx.......... Nagaraju

        T M 2 Replies Last reply
        0
        • N Nagaraju_Focus

          Thanks Maharishi, But I need to Save the whole table Data into a xml file which is to be created with a sql query. means Select * from TableName to "c:\test.xml" I need a query to send whole sql table to cml file is there any way to do like that? thx.......... Nagaraju

          T Offline
          T Offline
          Tobias Schoenig
          wrote on last edited by
          #4

          I don't know wether you can achieve this with a sql statement, but if your're using a .NET-application , to send the SQL Statement, you could do the following: - Fill a DataSet via SqlDataAdapter with the output of your Select-statement - Write the data to a xml-file using the DataSet.WriteXML()-method. This would solve your problem in a very easy way, but if you really need to do that in one sql-statement I haven't got the faintest idea. Tobias

          1 Reply Last reply
          0
          • N Nagaraju_Focus

            Thanks Maharishi, But I need to Save the whole table Data into a xml file which is to be created with a sql query. means Select * from TableName to "c:\test.xml" I need a query to send whole sql table to cml file is there any way to do like that? thx.......... Nagaraju

            M Offline
            M Offline
            Maharishi Bhatia
            wrote on last edited by
            #5

            Hi, For that you will need to write a PL/SQL for this kind of stuff. In MS SQL 2000/2005 there is an extended stored proc named xp_cmdshell which can be used to access the windows command line which can be used to save file. I have got an example which you can use for this... DECLARE @FileName varchar(50), @bcpCommand varchar(2000) SET @FileName = 'c:\data.txt' SET @bcpCommand = 'bcp "SELECT * FROM TableName for xml auto" queryout "' SET @bcpCommand = @bcpCommand + @FileName + '" -U sa -P pwd -c' EXEC master..xp_cmdshell @bcpCommand But for this kind of extended proc access the procedure has to run in 'sa' context... or you need administrator rights to do that... Hope this helps Maharishi

            Nothing is Impossible. Even impossible spells "i m possible"

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups