This is the first time I'm using 'For XML Path' in a SQL script. I'm close with the script but I just can't figure out how to get the XML to format correctly. Any idea what I'm doing wrong?
This is what I need.
<RecordsManager>
<RecordSeries Id="41477">
<RecordCategory Id="41477-104249">
<Record Define="yes" Id="0001">
<Record Define="yes" Id="0001" ResponsibleUser="BFRANKLIN"/>
<Record Define="yes" Id="0002" ResponsibleUser="BFRANKLIN"/>
</Record>
</RecordCategory>
</RecordSeries>
</RecordsManager>
This is what I get. It's not putting in the END tag in each ResponsibleUser Record and is adding too many '</Record' tags.
<RecordsManager>
<RecordSeries Id="10070">
<RecordCategory Id="10070-9452">
<Record>
<Record Define="yes" Id="0001">
<Record Define="yes" Id="0001" ResponsibleUser="BFRANKLIN">
<Record Define="yes" Id="0002" ResponsibleUser="BFRANKLIN"/>
</Record>
</Record>
</Record>
</Record>
</Record>
</RecordCategory>
</RecordSeries>
This is the script I'm using.
SELECT
RecordSeriesId as [RecordSeries/@Id]
, RecordCategoryId as [RecordSeries/RecordCategory/@Id]
,'yes' as [RecordSeries/RecordCategory/Record/@Define]
,'0001' as [RecordSeries/RecordCategory/Record/@Id]
,'yes' as [RecordSeries/RecordCategory/Record/Record/@Define]
,'0001' as [RecordSeries/RecordCategory/Record/Record/@Id]
, [ResponsibleUser] as [RecordSeries/RecordCategory/Record/Record/@ResponsibleUser]
,'yes' as [RecordSeries/RecordCategory/Record/Record/Record/@Define]
,'0002' as [RecordSeries/RecordCategory/Record/Record/Record/@Id]
, [ResponsibleUser] as [RecordSeries/RecordCategory/Record/Record/Record/@ResponsibleUser]
FROM Q_ChangeMatter
WHERE RecordSeriesId = '10070'
FOR xml path(''), ROOT('RecordsManager')
Prior to version 5.0, MySQL XML support was limited to exporting data in XML format using the MySQL command line client. Executing a command or query using the --xml or -X option told the MySQL client utility to produce the output as XML data. For instance, the following line would output all of the database variables that begin with the string “version”.
C:>mysql -u -p -e "SHOW VARIABLES LIKE '%version%'" –-xml