请尝试以下解决方案。
因为没有提供 DDL 和样本数据填充,所以假设Details列是 XML 数据类型。
SQL
-- DDL and sample data population, start
DECLARE @tbl TABLE (ID INT IDENTITY PRIMARY KEY, Label VARCHAR(20), Details XML);
INSERT INTO @tbl (Label, Details) VALUES
('Test1',N'<terms><destination><email>email11@foo.com</email><email>email12@foo.com</email></destination><content>blabla</content></terms>'),
('Test2',N'<terms><destination><email>email21@foo.com</email><email>email22@foo.com</email></destination><content>blabla</content></terms>');
-- DDL and sample data population, end
SELECT ID, Label
, REPLACE(Details.query('data(/terms/destination/email/text())').value('.','VARCHAR(MAX)'), SPACE(1), ', ') AS Destination
FROM @tbl;
输出
+----+-------+----------------------------------+
| ID | Label | Destination |
+----+-------+----------------------------------+
| 1 | Test1 | email11@foo.com, email12@foo.com |
| 2 | Test2 | email21@foo.com, email22@foo.com |
+----+-------+----------------------------------+