我正在使用SQL Server 2012,有以下两个表 9 @' d- u ~3 _2 h; k2 h博客 ) k7 {) F! s+ k6 N5 C" EId Title1 My Blog Title博客内容 5 d# |; P3 [$ k2 h- EId Blogid Content1 1 My First Paragraph7 J* `5 A9 M+ W. U
2 1 My Second Paragraph G; y5 ]# i m$ s) V3 T每个Blog可能有多个条目Content条目。这是一个varchar包含HTML内容字段。我需要选择一个博客,并将所有内容结合在一起。 , b" I4 b% G1 r这是我试过的: ) Q# F4 C: s/ A" R- {. Y) KSELECT B.Id,B.Title,STUFF(( SELECT BC.Content FROM BlogContent BC WHERE B.Id = BC.Blogid ORDER BY BC.Id ASC OFFSET 0 ROWS FOR XML PATH('),1,0,AS ContentFROM Blog BWHERE B.Id = 1ORDER BY B.PublishDate DESC这是我的结果: ! A, i5 R$ r0 H+ {Id Title Content1 My Blog Title <p>This is the first Message</p><p>This is the second Message</p>我上面的代码的问题是,一切都变成了HTML我想是因为编码FOR XML。如何在不添加此部分的情况下合并?如果不添加,就会出错。# F" B. W7 M, k9 a 子查询返回超过1个值。当子查询遵循=,!=,,> =不允许将子查询用作表达式。9 g" L* H5 E' G6 b/ A1 C 如何获得以下结果: . ~3 D. o$ }1 N6 o4 p& q1 mId Title Content1 My Blog Title This is the first Message 6 p; O: C' l/ q; qThis is the second Message # e% w9 L- H) H8 f1 D 4 T" P" m- r) T3 v0 b/ R 解决方案: