我有一個3行的表,1被用作行標識符,第2個被用來做與其他表的關係,第3個擁有內容。我正在做一個查詢,其中給定的結果是我需要的,但有一點點的錯誤。無法管理從數據庫導出多行到XML
下面是我使用的查詢:
SELECT Plate, tbl_veiculos.ID, Section, Category, Brand, Model, Version, Fuel, Price, B2BPrice, Year, Month, TollClass, Origin, Color, SeatColour, Seats, Kms, Doors, HP, Owners, CC, Obs, TaxDeductible, WarrantyMonth,
(SELECT Name, Street, Locality, Email from tbl_AdStand where tbl_AdStand.ID = tbl_veiculos.ID AND tbl_veiculos.ID = 1 FOR XML PATH('AdStand'), type),
(SELECT DISTINCT Site from tbl_ExportSites where tbl_ExportSites.ID = tbl_veiculos.ID AND tbl_veiculos.ID = 1 FOR XML PATH('ExportSites'), type)
FROM tbl_veiculos, tbl_veiculo_spec, tbl_AdStand
WHERE tbl_veiculos.ID = tbl_veiculo_spec.ID AND tbl_AdStand.ID = tbl_veiculos.ID AND tbl_veiculos.ID = 1
FOR XML PATH ('Vehicle'), TYPE, ROOT('VehicleList')
下面是我得到的輸出:
<VehicleList>
<Vehicle>
<Plate>34-23-nd</Plate>
<ID>1</ID>
<Section>carros</Section>
<Category>cabrio</Category>
<Brand>Mercedes-Benz</Brand>
<Model>A140</Model>
<Version>1.4 twin-turbo</Version>
<Fuel>Gasolina</Fuel>
<Price>18.000</Price>
<B2BPrice>0</B2BPrice>
<Year>2015</Year>
<Month>03</Month>
<TollClass>2</TollClass>
<Origin>Alemanha</Origin>
<Color>Vermelho</Color>
<SeatColour>Cinza</SeatColour>
<Seats>5</Seats>
<Kms>13000</Kms>
<Doors>5</Doors>
<HP>310</HP>
<Owners>0</Owners>
<CC>1.389</CC>
<Obs>Tinta raspada no para-choques dianteiro</Obs>
<WarrantyMonth>0</WarrantyMonth>
<AdStand>
<Name>Stand Veloso</Name>
<Street>Rua dos Biscainhos</Street>
<Locality>2450-341</Locality>
<Email>[email protected]</Email>
</AdStand>
<ExportSites>
<Site>Coisas</Site>
</ExportSites>
<ExportSites>
<Site>Custojusto</Site>
</ExportSites>
<ExportSites>
<Site>StandVirtual</Site>
</ExportSites>
</Vehicle>
</VehicleList>
的 「錯誤」 是在上線
<ExportSites>
<Site>Coisas</Site>
</ExportSites>
<ExportSites>
<Site>Custojusto</Site>
</ExportSites>
<ExportSites>
<Site>StandVirtual</Site>
</ExportSites>
輸出apears「分離」,而我需要absolutelly相反,我需要它看起來像這樣[硬編碼]:
<ExportSites>
<Site>Coisas</Site>
<Site>Custojusto</Site>
<Site>StandVirtual</Site>
</ExportSites>
什麼我需要在我的查詢來改變,讓我得到這個。另外,我可以稍後使用PHP將此查詢導出爲XML文件嗎?
謝謝你的時間。
下一次,當你把一個問題,請把它降低到最低限度所需。所有不需要指出問題的列都應該刪除。只是讓其中一個或兩個到位以顯示結構... – Shnugo