使用select语句在表值函数中传递参数

时间:2021-05-06 18:02:15

I have created a table valued return function which returns me a table . here is call of my function as follow

我创建了一个表值返回函数,它返回一个表。下面是我的函数调用

SELECT * FROM dbo.[StateFixedTaxesCalculation](3020,16,1,1006)

and its working OK for me , now i want to use this function call in a select statment , so i can pass 16 which is basically employeeId dynamically.

它对我来说没问题,现在我想在select语句中使用这个函数调用,所以我可以通过16,这基本上是动态的employeeId。

So i have decided to use inner join with table returned by that function . Like this

所以我决定使用这个函数返回的表的内部连接。像这样

SELECT * FROM Employee as E
INNER JOIN  dbo.[StateFixedTaxesCalculation](3020,16,1,1006) as TC   ON TC.EmployeeId=E.EmployeeId

but now how can i pass 16 as dynamic value of all employeeId one by one .

但是现在我如何通过16作为所有employeeId的动态值。

1 个解决方案

#1


58  

use outer/cross apply:

使用外部/交叉应用:

select *
from Employee as E
    cross apply dbo.[StateFixedTaxesCalculation](3020, E.EmployeeId, 1, 1006) as TC

if you still have to filter by TC.EmployeeId = E.EmployeeId, you can do this with subquery:

如果你还要通过TC过滤。EmployeeId = E。EmployeeId,你可以用子查询来做这个:

select *
from Employee as E
    cross apply (
        select TT.*
        from dbo.[StateFixedTaxesCalculation](3020, E.EmployeeId, 1, 1006) as TT
        where TT.EmployeeId = E.EmployeeId
    ) as TC

#1


58  

use outer/cross apply:

使用外部/交叉应用:

select *
from Employee as E
    cross apply dbo.[StateFixedTaxesCalculation](3020, E.EmployeeId, 1, 1006) as TC

if you still have to filter by TC.EmployeeId = E.EmployeeId, you can do this with subquery:

如果你还要通过TC过滤。EmployeeId = E。EmployeeId,你可以用子查询来做这个:

select *
from Employee as E
    cross apply (
        select TT.*
        from dbo.[StateFixedTaxesCalculation](3020, E.EmployeeId, 1, 1006) as TT
        where TT.EmployeeId = E.EmployeeId
    ) as TC