将列作为函数参数传递

时间:2022-08-31 20:36:08

I am having an issue with passing the ta.customer_no as a parameter to the function that generates a table, which I am joining to ta.

我有一个问题,将ta.customer_no作为参数传递给生成表的函数,我正在加入ta。

SELECT 
    ta.customer_no,
    ta.first_name,
    tb.company_name
FROM
    table01 ta
JOIN   
    dbo.FUNC01(ta.customer_no) tb ON ta.customer_no = tb.customer_no;

The error:

Msg 4104, Level 16, State 1, Line 13
The multi-part identifier "ta.customer_no" could not be bound.

消息4104,级别16,状态1,行13无法绑定多部分标识符“ta.customer_no”。

Why can't it be bound?

为什么不能受约束?

Thanks a bunch!

谢谢你!

1 个解决方案

#1


1  

I think you should use "cross apply" instead of "join", like the following

我认为你应该使用“交叉申请”而不是“加入”,如下所示

SELECT 
       ta.customer_no,
       ta.first_name,
       tb.company_name
FROM   table01 ta
CROSS APPLY dbo.FUNC01( ta.customer_no ) tb 
WHERE ta.customer_no=tb.customer_no;

As for why "cannot be bound", it is related to SQL Engine's processing logic order. In short, the "Join" operator is processed before "Select" operator, thus "Join" operator cannot recognize "ta.customer_no"

至于为什么“不能绑定”,它与SQL Engine的处理逻辑顺序有关。简而言之,“加入”运算符在“选择”运算符之前处理,因此“加入”运算符无法识别“ta.customer_no”

#1


1  

I think you should use "cross apply" instead of "join", like the following

我认为你应该使用“交叉申请”而不是“加入”,如下所示

SELECT 
       ta.customer_no,
       ta.first_name,
       tb.company_name
FROM   table01 ta
CROSS APPLY dbo.FUNC01( ta.customer_no ) tb 
WHERE ta.customer_no=tb.customer_no;

As for why "cannot be bound", it is related to SQL Engine's processing logic order. In short, the "Join" operator is processed before "Select" operator, thus "Join" operator cannot recognize "ta.customer_no"

至于为什么“不能绑定”,它与SQL Engine的处理逻辑顺序有关。简而言之,“加入”运算符在“选择”运算符之前处理,因此“加入”运算符无法识别“ta.customer_no”