结果字段之一在其中包含多个html引用,例如下面的代码。当前结果集如下:
Supervisor Employee
----------- --------
Supervisor1 <td><br>Employee1<td><br>Employee2<td><br>Employee3</table>
Supervisor2 <td><br>Employee1<td><br>Employee2</table>
Supervisor3 <td><br>Employee1<td><br>Employee2<td><br>Employee3<td><br>Employee4</table>
所需的输出:
Supervisor Employee
----------- --------
Supervisor1 Employee1 || Employee2 || Employee3
Supervisor2 Employee1 || Employee2
Supervisor3 Employee1 || Employee2 || Employee3 || Employee4
示例查询:
create table #Temp
(
Supervisor varchar(200),
Employee Varchar(200),
)
INSERT INTO #Temp
VALUES ('Supervisor1', '<td><br>Employee1<td><br>Employee2<td><br>Employee3</table>')
, ('Supervisor2', '<td><br>Employee1<td><br>Employee2</table>')
, ('Supervisor3', '<td><br>Employee1<td><br>Employee2<td><br>Employee3<td><br>Employee4</table>')
select * from #temp
drop table #temp
您似乎想删除HTML标签。您可以明确地这样做:
select t.*,
replace(replace(employee, '<td><br>', ' '), '</table>', '') as employees
from t;
我在想:
SELECT
Supervisor = t.Supervisor,
Employee = REPLACE(REPLACE(REPLACE(t.Employee,'<td>',''),'</table>',''),'<br>',' || ')
FROM #Temp AS t;
返回:
Supervisor Employee
--------------- -----------------------------------------------------------
Supervisor1 || Employee1 || Employee2 || Employee3
Supervisor2 || Employee1 || Employee2
Supervisor3 || Employee1 || Employee2 || Employee3 || Employee4
您可以像这样更新您的数据。
UPDATE #Temp
SET Employee = REPLACE(REPLACE(REPLACE(Employee,'<td>',''),'</table>',''),'<br>','||');