我有一个名为fn_SplitCommaSep的表值函数,它用逗号分隔文本字段(从'a,b,c'到3行:abc)
如何将此表连接到表中,将表列作为输入?
出于此目的,假设表MyTable有2列Id和TextWithCommas,并且表值函数fn_SplitCommaSep生成一个名为TextWithoutComma的列
例如.类似于其中之一的东西
select fs.TextWithoutComma
from fn_SplitCommaSep(select mt.TextWithCommas from MyTable) fs
Run Code Online (Sandbox Code Playgroud)
要么
select fs.TextWithoutComma, mt.Id
from MyTable mt
inner join fn_SplitCommaSep(mt.TextWithCommas) fs on (something)
Run Code Online (Sandbox Code Playgroud)
Per*_* P. 24
在数据库中存储逗号分隔值,请查看APPLY
所以类似于:
SELECT fs.TextWithoutComma, mt.Id
FROM MyTable mt
CROSS APPLY fn_SplitCommaSep(mt.TextWithCommas) AS fs
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19818 次 |
| 最近记录: |