[英]SQL Join table-valued function with table where table field is a function input
我有一个名为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
要么
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.