Search code examples
sql-serverxmlsql-server-2005unixodbc

Any Linux SQL Server client (command line) which supports XML formatting?


I have to launch some batch queries from a Red Hat Server against SQL Server 2005 and I need to format the results in an XML file. I have installed msodbcsql and unixODBC in my red hat server and I can access the SQL Server via isql. The driver works well and I can launch SQL Server in batch mode and save the results to a file.

However isql only supports to use a delimiter character (-d option) or html format (-w option). I need the output in XML format tagging each column.

Any help? Thanks in advance!


Solution

  • SQL Server 2005 was the first version which supported native XML queries.

    Try a query like this:

    SELECT 'attr' AS [@SomeAttribute]
          ,'test' AS SomeElement 
    FOR XML PATH('testPath'),ROOT('testRoot');
    

    The result should be this:

    <testRoot>
      <testPath SomeAttribute="attr">
        <SomeElement>test</SomeElement>
      </testPath>
    </testRoot>
    

    If this works, it should be easy to get any XML from SQL Server...

    From your question I take, that your tool can deal with markups using the -w option. I'd try this...