I'm working on a procedure that returns a field in XML, so far nothing 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 as I need to repeat a process through a cursor, I do not know how to do 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. Actually the SQL statement I am putting together is called by a Trigger and needs to gather data to populate an XML field from another table . The biggest problem is that I only know of a way to assemble an XML by T-SQL, this form is concatenating strings and later transforming into XML.