Start here:
declare @XMLTest table( [Name] [nvarchar](50) NOT NULL )
INSERT @XMLTest ([Name]) VALUES (N'One')
INSERT @XMLTest ([Name]) VALUES (N'Two')
INSERT @XMLTest([Name]) VALUES (N'Three')
select * from @xmltest for xml auto
Returns in XML format.
Or just some lame concatenation.
declare @XMLTest table( [Name] [nvarchar](50) NOT NULL )
INSERT @XMLTest ([Name]) VALUES (N'One')
INSERT @XMLTest ([Name]) VALUES (N'Two')
INSERT @XMLTest([Name]) VALUES (N'Three')
select '<' + Name + '/>' from @xmltest
It would help if your objective were more clear.
This query provides more guidance on how to custom format the XML stuff.
create table #xmltest (nID int primary key identity, [Name] [nvarchar](50) NOT NULL )
create table #xmldemo (Tag varchar, Parent Varchar, Other Varchar);
declare @i as int = 1;
INSERT #XMLTest ([Name]) VALUES (N'One')
INSERT #XMLTest ([Name]) VALUES (N'Two')
INSERT #XMLTest([Name]) VALUES (N'Three')
while (@i < 3)
begin
declare @tag as varchar(100) = '[Test!1!' + (select name from #XMLTest where nID = @i) + '!ELEMENT]';
declare @dsql as varchar(max) = 'select 1 as Tag, null as Parent, ''this'' as ' + @tag + ' from #xmltest for xml explicit';
exec(@dsql);
set @i += 1;
end
select * from #xmldemo;
drop table #xmldemo;
drop table #xmltest;
There's a little bit of extra stuff in there that's not pertinent, but it demonstrates something like what you're attempting.