English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi,
I have a sql query which works fine but I don't know how to save it as xml. Can anyone please help.

sql="SELECT ID,Name, FROM User for XML"

it gives me the following error
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 'XML'.

2007-03-14 01:23:25 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

This applies to MS SQL Server 2005;
First a simple query such as:
"SELECT ID, Name FROM User FOR XML AUTO" would create a XML query for you;
You could of course create a XML Datatype which takes the result such as:
DECLARE @result AS XML;
SET @result = (SELECT ID, Name FROM User FOR XML AUTO);
Remember that the Root Node and the XML Declaration are not created by default; so you need to add them to the stream;
My suggestion is that you create a CLR application; create a stored procedure which returns the XML Query; then in your .NET CLR Application, you create a StreamWriter which will add the XML Declaration Line and the Root Node to the stream, append the stored procedure output to the stream and finally closes the stream by adding the closing Tag for the XML Root Node.

2007-03-14 01:38:05 · answer #1 · answered by Coosa 2 · 1 0

sql="SELECT ID,Name FROM User for XML AUTO"

there is no comma after Name, and try adding AUTO/RAW at the end.

2007-03-14 01:36:14 · answer #2 · answered by Zlavzilla 3 · 1 0

You can't use "for" as part of a field name

2007-03-14 01:28:24 · answer #3 · answered by A A 3 · 0 0

fedest.com, questions and answers