December 14, 2011 at 3:04 pm
I need an XML element that has an attribute and an element value. The result required is such:
<Party>
<CustomerID Role="SENDER">1122334455</CustomerID>
<Name>SomeOne</Name>
<Address1>SomeWhere</ADDRESS>
<City>SomeCity</City>
</Party>
This is a subquery in part of a larger SQL XML query, the data is static so no table is referenced. The DB is SQL Server 2005.
The query I am using is:
(
SELECT
'SENDER''CustomerID/@Role',
'1122334455''CustomerID',
'SomeOne''Name',
'SomeWhere''Address1',
'SomeCity''City'
) FOR XML path ('Party')
But the result is:
<Party>
<CustomerID Role="SENDER">
</CustomerID>
<Name>SomeOne</Name>
<Address1>SomeWhere</Address1>
<City>SomeCity</City>
</Party>
Any ideas on what is missing or wrong with my query?
December 15, 2011 at 2:52 am
Brent Seeney-273128 (12/14/2011)
I need an XML element that has an attribute and an element value. The result required is such:<Party>
<CustomerID Role="SENDER">1122334455</CustomerID>
<Name>SomeOne</Name>
<Address1>SomeWhere</ADDRESS>
<City>SomeCity</City>
</Party>
This is a subquery in part of a larger SQL XML query, the data is static so no table is referenced. The DB is SQL Server 2005.
The query I am using is:
(
SELECT
'SENDER''CustomerID/@Role',
'1122334455''CustomerID',
'SomeOne''Name',
'SomeWhere''Address1',
'SomeCity''City'
) FOR XML path ('Party')
But the result is:
<Party>
<CustomerID Role="SENDER">
</CustomerID>
<Name>SomeOne</Name>
<Address1>SomeWhere</Address1>
<City>SomeCity</City>
</Party>
Any ideas on what is missing or wrong with my query?
When running your example, I'm getting exactly the result you're looking for (see attached screenshot).
December 15, 2011 at 12:05 pm
I get the expected result as well. What version of SQL Server are you running this on? I ran it on SQL Server 2008 R2 (RTM)
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
December 20, 2011 at 4:26 pm
Hi Guys
I was using SQL Manager from EMS rather than SQL Server Management Studio, and it turns out that they give different outputs.
I had been so confounded by this problem because it should have worked!
I will keep in mind to check everything with SQL Management Studio in future.
Thanks very much for your help 🙂
December 20, 2011 at 7:57 pm
Brent Seeney-273128 (12/20/2011)
Hi GuysI was using SQL Manager from EMS rather than SQL Server Management Studio, and it turns out that they give different outputs.
I had been so confounded by this problem because it should have worked!
I will keep in mind to check everything with SQL Management Studio in future.
Thanks very much for your help 🙂
Considering the wrong answers you just got from it, is there some significant advantage to using SQL Manager from EMS over SSMS?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply