7
I am working on a project that returns an XML field, so far not bad. The problem arises when I have initial data coming from a query and intermediate data coming from another query.
I tried to solve with string concatenation and then convert to XML, but since I need to repeat a process through a cursor, I don’t know how to make this concatenation.
DECLARE @XML_RETORNO XML;
SET @XML_RETORNO = '<root>'
+'<nome>Marcelo</nome>'
+'<itens>'
-- Quero começar um cursor aqui
+'<item tipo="carro">Fusca</item>'
+'<item tipo="carro">Gol</item>'
+'<item tipo="moto">CG-150</item>'
-- Termino do cursor
+'</itens>'
+'</root>';
SELECT CAST(@XML_RETORNO AS XML)
Edited
This example is just an illustration of what I need. In fact the SQL statement I’m mounting is called by a Trigger and needs to gather data to fill a XML field of another table. The biggest problem is that I only know one way to mount an XML by T-SQL, this way is by concatenating strings and later transforming into XML.
Post your code (the relevant part)!
– Tiago César Oliveira
I edited the code, it is an easier example to understand, in fact the code is much more extensive.
– 2madera
You came to try
FOR XML...
?– bfavaretto