|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, June 03, 2011 9:11 AM
Points: 64,
Visits: 104
|
|
Hello, I am trying to create an xml from a table with tags for each field in the table. Basically i am trying to run following query in SQL Server 2005
SELECT * FROM customer FOR XML AUTO, ELEMENTS, ROOT('customers')
This gives an error.
Line 2: Incorrect syntax near 'ROOT'.
I think ROOT command is correct so not sure where the problem is. Do i need to change any settings on SQL Server?
Thanks, Ramesh.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 8:36 AM
Points: 2,224,
Visits: 4,094
|
|
The "ROOT" keyword is only available with the "RAW" option and is not available with the "AUTO" option.
SQL = Scarcely Qualifies as a Language
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 10:02 AM
Points: 38,086,
Visits: 30,381
|
|
Check that the compatability mode of the database you're running this in is set to 90
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, June 03, 2011 9:11 AM
Points: 64,
Visits: 104
|
|
I tried with RAW this also fails...
SELECT * FROM customer FOR XML RAW, ELEMENTS, root('customers')
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:29 PM
Points: 2,278,
Visits: 3,011
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 8:36 AM
Points: 2,224,
Visits: 4,094
|
|
I am not having a problem and here is test case.
select database_id,name from master.sys.databases where database_id <= 5 FOR XML AUTO, ELEMENTS, ROOT('databases')
SQL = Scarcely Qualifies as a Language
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:29 PM
Points: 2,278,
Visits: 3,011
|
|
Ramesh,
I do not know if you have resolved this issue, but the reason we want you to check your compatibility level is because the new SQL 2005 features are not available in compatability mode 80.
My blog: http://jahaines.blogspot.com
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, June 03, 2011 9:11 AM
Points: 64,
Visits: 104
|
|
All, Thanks for your valuable inputs. I Asked DBA's to change compatability level to 90 but he did not agree as he is not sure if that would cause any other issues. I created a new test database in SQL Server 2005 and was able to use ROOT command in that database. Other database (created using SQL Server 2000) on same server gives error.
|
|
|
|