Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Select into XML
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01538838
Message ID:
01538843
Vues:
16
>>>>Hi,
>>>>
>>>>Can you see what is wrong with the following SQL Select that outputs into XML? The error I get (in the calling routine) that the XML has multiple root element. Another thing is that in the SQL Server query window the first name (USER_NAME) is shown in a different color (looks like purple).
>>>>
>>>>
>>>>SELECT USER_NAME "USER_NAME", USER_EMAIL "USER_EMAIL", USER_CC "USER_CC", 
>>>>USER_PHONE "USER_PHONE", USER_BLDG "USER_BLDG", USER_FLOOR "USER_FLOOR",
>>>>USER_ROOM "USER_ROOM" FROM USERINFO WHERE COOKIE_ID = @CookieId FOR XML PATH ('') 
>>>>
>>>>
>>>>TIA.
>>>
>>>USER_NAME is a function in SQL Server. Now, do you have a field making each row unique? If not, XML PATH is getting confused.
>>
>>The table has a PK field which makes each row/field unique. Do I understand correctly that the fact that one of the columns in the table has the same name as a function in SQL Server causes the error with "multiple root elements" ?
>
>No, this is not it. For now, remove all aliases (since they are the same as field names) and add that PK field to the query.

Adding ROOT('USERS') eleminated the error. But now my code that parses the XML fails. So I have to figure what is wrong with my code that loads XML (I am using xdoc.LoadXml( XmlFileString). Maybe I will have to start a new thread for that. Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform