Using FOR XML AUTO against a synonym
Posted
by Rick
on Stack Overflow
See other posts from Stack Overflow
or by Rick
Published on 2010-06-15T23:46:42Z
Indexed on
2010/06/15
23:52 UTC
Read the original article
Hit count: 239
We've just switched to synonyms for linked server stuff, and noticed that our FOR XML output is no longer correct. When returning XML results from a view, we could alias the view and that would be assigned as the element name. With synonyms, however, it seems to ignore the alias? We're still mostly on SQL 2005 - this bug doesn't seem to happen on our 2008 instance. Is this a known problem, and any ideas for work-arounds?
For example, this is what we used to be able to do:
select top 3 number from Numbers as elementname for xml auto
<elementname number="0"/><elementname number="1"/><elementname number="2"/>
And this is what happens with a synonym:
select top 3 number from Numbers_synonym as elementname for xml auto
<dbo.Numbers number="0"/><dbo.Numbers number="1"/><dbo.Numbers number="2"/>
As you can see, SQL Server seems to use the name of the actual referenced object instead of the alias. This gets worse for cross server queries, because you get the four-part name instead of the nice alias. (eg: <rick_server.rick_database.dbo.Numbers number="0"/>
...)
© Stack Overflow or respective owner