I have the following SQL query that I'm having trouble explicitly defining the shape for
select tableName, uqName, col1, col2
from someTable
I would like to select the results into XML as below. I need the col1 and col2 to show up as children and tableName and uqName to show up as attributes. If col1 or col2 is null then I need to specify an IsNull attribute. Otherwise the value is selected as a text node as the child of the Col element
One row returned from the above SQL would look like this:
<UniqueKey Name="UniqueKeyName" TableName="TableName" >
<Col Name="col1" IsNull="true" />
<Col Name="col2">ABC</Col>
</UniqueKey>
How can I explicitly define this XML shape using SQL Server 2008 R2?
COALESCEfunction right?SELECTor can you select into a buffer/file/pipe/etc. and then work on that to shape the result?