我有一个包含HTML标记的表。 我只想创建一个使用此表的HTML FORM是HTML FOrmat 例如。
ID Tags
-- ----
1 Html
2 Head
3 Title
4 Meta
5 Body
6 Font
结果应为
ID HTML
-- ------------------------------------------------------------------------------------
1 <Html> <Head> <Title></Title> <Meta></Meta> </Head><Body> <Font></Font></Body</Html>
答案 0 :(得分:1)
declare @t table(id int, tags varchar(50))
insert into @t values
(1, 'Html'),
(2, 'Head'),
(3, 'Title'),
(4, 'Meta'),
(5, 'Body'),
(6, 'Font')
;with Tags1 as
(
select xml1 = (select '<' + tags + '>' from @t for xml path (''))
)
,Tags2 as
(
select xml2 = (select '</' + tags + '>' from @t order by id desc for xml path (''))
)
select replace(replace(Tags1.xml1 + Tags2.xml2,'<','<'),'>','>')
from Tags1, Tags2