对表的每条记录调用 TVF 并连接结果 [英] Call TVF on every record of a table and concat results

查看:22
本文介绍了对表的每条记录调用 TVF 并连接结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这一定很明显,但我无法弄清楚.

I thought that must be obvious but I can't figure it out.

假设有一个表 tblData 有一个列 ID 和一个表值函数(_tvf),它接受一个 ID 作为参数.我需要 tblData 中所有 ID 的结果.

Say there is a table tblData with a column ID and a table-valued-function (_tvf) that takes an ID as parameter. I need the results for all ID's in tblData.

但是:

SELECT * FROM tblData data 
INNER JOIN dbo._tvf(data.ID) AS tvfData
   ON data.ID = tvfData.ID

给我一​​个错误:无法绑定多部分标识符data.ID"

将所有 ID 传递给此 TVF 并连接结果的正确方法是什么?

What is the correct way to pass all ID's to this TVF and concat the results?

谢谢

推荐答案

我认为您可能需要在这里使用 CROSS APPLY 而不是内部联接:

I think you might need to use CROSS APPLY instead of an inner join here:

SELECT * 
FROM dbo.tblData data 
CROSS APPLY dbo._tvf(data.ID) AS tvfData

这将为基表的每个 data.ID 调用 TVF 函数,并将结果连接到基表的列.

This will call the TVF function for each data.ID of the base table and join the results to the base table's columns.

在此处查看资源:

这篇关于对表的每条记录调用 TVF 并连接结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆