SQL如何将ID列添加到Split选择中

时间:2017-06-14 23:47:02

标签: sql sql-server split

我有以下查询:

SELECT s FROM dbo.Split(',',(
select 
emp.Data
FROM Employee emp
WHERE EmployeeID = 56640
))

“数据”列是逗号分隔值:

emp.Data has the value: '461086,461104'

返回下表:

enter image description here

现在,我需要添加到此选择EmployeeID列,所以我需要这样的东西

SELECT s FROM dbo.Split(',',(
select 
emp.EmployeeId,
emp.Data
FROM Employee emp
WHERE EmployeeID = 56640
))

但这给了我一个错误。

有任何线索吗?

1 个答案:

答案 0 :(得分:0)

您正在寻找cross apply

select emp.EmployeeId, s.val
FROM Employee emp CROSS APPLY
     dbo.split(',', emp.data) s(val)
WHERE emp.EmployeeID = 56640;