SQLTeam.com | Weblogs | Forums

SQL select to comply with XML standard according to W3C

xml
sql2008

#1

Hello,
I have a select that generates an xml like this:

<Fund_Lib_ultima_fecha>
  <LoadedDateTime >2017-07-30T19:03:37.803</LoadedDateTime>
</Fund_Lib_ultima_fecha>

and I get this result by using the "for xml" clause after the select.

My question is:

Can I include in the output the column type?
This would look like:

<Fund_Lib_ultima_fecha>
  <LoadedDateTime Type="C">2017-07-30T19:03:37.803</LoadedDateTime>
</Fund_Lib_ultima_fecha>

Many thanks,
pepe


#2
SELECT
	'C' AS [LoadedDateTime/@Type],
	GETDATE() AS [LoadedDateTime]
FOR XML PATH('Fund_Lib_ultima_fecha')

#3

thank you!