我有一个名为 fn_SplitCommaSep 的表值函数,它用逗号分隔文本字段(从“a、b、c”到 3 行:a b c)
如何将其连接到表中,将表列作为输入?
为此,假设表 MyTable 有 2 列,即 Id 和 TextWithCommas,并且表值函数 fn_SplitCommaSep 生成一列名为 TextWithoutComma
例如。像其中之一
select fs.TextWithoutComma
from fn_SplitCommaSep(select mt.TextWithCommas from MyTable) fs
or
select fs.TextWithoutComma, mt.Id
from MyTable mt
inner join fn_SplitCommaSep(mt.TextWithCommas) fs on (something)
将逗号分隔值存储在数据库中,看看APPLY
所以像这样:
SELECT fs.TextWithoutComma, mt.Id
FROM MyTable mt
CROSS APPLY fn_SplitCommaSep(mt.TextWithCommas) AS fs
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)