SELECTing multiple values for the same attribute using FOR XML in SQL

HICHAMOS

New Member
I'm attempting to retrieve data from a SQL table as XML. Consider the following table: \[code\] Customers Id Last First Phone1 Phone2 10 Doe John 555-2121 555-614533 Smith Sally 555-3333 555-7000\[/code\]I'd like to retrieve the Last, First, Phone1, and Phone2 fields using the FOR XML clause in SQL. However, I'd like to retrieve the Phone2 field with an attribute of "Evening". For example, I'd like the XML to look like:\[code\]<Customers> <Customer> <Last>Doe</Last> <First>John</First> <Phone Type="Daytime">555-2121</Phone> <Phone Type="Evening">555-6145</Phone> </Customer> </Customers> \[/code\]However, I'm unable to get it to work. Is there something I'm missing? Any and all help would be greatly appreciated!
 
Back
Top