SQL サーバーで xml を作成し、正常に動作するクエリがあります。問題は、それをファイルに保存する必要があることです。これを行うと、フォーマットが破損します。
SELECT mydata.dbo.tblBooking.ID, mydata.dbo.tblBooking.ReservationID, mydata.dbo.tblBooking.EventName, mydata.dbo.tblBooking.TimeEventStart, mydata.dbo.tblBooking.TimeEventEnd, mydata.dbo.tblRoom.Room,
mydata.dbo.tblReservation.TempContact, mydata.dbo.tblGroup.GroupName, mydata.dbo.tblUserDefinedField.FieldValue, mydata.dbo.tblEventType.Description
FROM
mydata.dbo.tblBooking INNER JOIN mydata.dbo.tblReservation ON mydata.dbo.tblBooking.ReservationID = mydata.dbo.tblReservation.ID
INNER JOIN mydata.dbo.tblEventType ON mydata.dbo.tblBooking.EventTypeID = mydata.dbo.tblEventType.ID
INNER JOIN mydata.dbo.tblGroup ON mydata.dbo.tblReservation.GroupID = mydata.dbo.tblGroup.ID
INNER JOIN mydata.dbo.tblUserDefinedField ON mydata.dbo.tblBooking.ReservationID = mydata.dbo.tblUserDefinedField.ParentID
INNER JOIN mydata.dbo.tblRoom ON mydata.dbo.tblBooking.RoomID = mydata.dbo.tblRoom.ID
where mydata.dbo.tblBooking.TimeEventStart between '2012-11-1' and '2012-12-20'
for xml Raw ,elements , ROOT ('EMSExport')
これが出力です
<EMSExport>
<row>
<ID>10891</ID>
<ReservationID>431</ReservationID>
<EventName>Bowery Mission Trip Wrap Party</EventName>
<TimeEventStart>2012-11-08T17:45:00</TimeEventStart>
<TimeEventEnd>2012-11-08T19:30:00</TimeEventEnd>
<Room>6-Conference </Room>
<TempContact>Keith Yagnik</TempContact>
<GroupName>Outreach</GroupName>
<FieldValue></FieldValue>
<Description>Meeting</Description>
</row>
<row>
<ID>10894</ID>
<ReservationID>434</ReservationID>
<EventName>SBJ Meeting</EventName>
<TimeEventStart>2012-11-06T11:45:00</TimeEventStart>
<TimeEventEnd>2012-11-06T12:30:00</TimeEventEnd>
<Room>6-Conference </Room>
<TempContact></TempContact>
<GroupName>Staff</GroupName>
<FieldValue></FieldValue>
<Description>Meeting</Description>
</row>
<row>
<ID>10888</ID>
<ReservationID>428</ReservationID>
<EventName>PCUSA missionary Cobbie Palm</EventName>
<TimeEventStart>2012-11-04T09:30:00</TimeEventStart>
<TimeEventEnd>2012-11-04T10:30:00</TimeEventEnd>
<Room>5-Corning Logan </Room>
<TempContact>Kate Dunn</TempContact>
<GroupName>Adult Education</GroupName>
<FieldValue></FieldValue>
<Description>Event</Description>
</row>
ファイルを保存する手順です。
declare @cmd nvarchar(2000);
select @cmd = 'bcp "EXEC EMSXMLraw" queryout "C:\testraw.xml" -x -c -t, -T -S MYshel\EM'
exec xp_cmdshell @cmd
これは出力ファイルの形式です
<EMSExport><row><ID>10891</ID><ReservationID>431</ReservationID><EventName>Bowery Mission Trip Wrap Party</EventName><TimeEventStart>2012-11-08T17:45:00</TimeEventStart><TimeEventEnd>2012-11-08T19:30:00</TimeEventEnd><Room>6-Conference </Room><TempContact>Keith Yagnik</TempContact><GroupName>Outreach</GroupName><FieldValue></FieldValue><Description>Meeting</Description></row><row><ID>10894</ID><ReservationID>434</ReservationID><EventName>SBJ Meeting</EventName><TimeEventStart>2012-11-06T11:45:00</TimeEventStart><TimeEventEnd>2012-11-06T12:30:00</TimeEventEnd><Room>6-Conference </Room><TempContact></TempContact><GroupName>Staff</GroupName><FieldValue></FieldValue><Description>Meeting</Description></row><row><ID>10888</ID><ReservationID>428</ReservationID><EventName>PCUSA missionary Cobbie Palm</EventName><TimeEventStart>2012-11-04T09:30:00</TimeEventStart><TimeEventEnd>2012-11-04T10:30:00</TimeEventEnd><Room>5-Corning Logan </Room><TempContact>Kate Dunn</TempContact><GroupName>Adult Education</GroupName><FieldValue></FieldValue><Description>Event</Description></row><row><ID>10263</ID><ReservationID>372</ReservationID><EventName>AA Christmas Lunch </EventName><TimeEventStart>2012-12-13T11:30:00</TimeEventStart><TimeEventEnd>2012-12-13T14:30:00</TimeEventEnd><Room>2-Bonnell </Room><TempContact>jimenez@amexclusive.com</TempContact><GroupName>Alcoholics Anonymous </GroupName><FieldValue>THISISTHEWEBDESCRIPTION</FieldValue><Description>Event</Description></row><row><ID>10817</ID><ReservationID>391</ReservationID><EventName>E.S.N. General Meeting</EventName><TimeEventStart>2012-11-13T18:30:00</TimeEventStart><TimeEventEnd>2012-11-13T20:30:00</TimeEventEnd><Room>3-Jones </Room><TempContact></TempContact><GroupName>FAPC</GroupName><FieldValue>Emergency Network of Shelters General Meeting</FieldValue>
すべての XML 形式が失われていることがわかりますが、どうすれば保持できますか?