我创建了一个表值返回函数,该函数返回一个表。这是我的函数调用如下
SELECT * FROM dbo.[StateFixedTaxesCalculation](3020,16,1,1006)
它对我来说工作正常,现在我想在select语句中使用此函数调用,因此我可以通过16它,基本上是employeeId动态的。
16
employeeId
因此,我决定将内部联接与该函数返回的表一起使用。像这样
SELECT * FROM Employee as E INNER JOIN dbo.[StateFixedTaxesCalculation](3020,16,1,1006) as TC ON TC.EmployeeId=E.EmployeeId
但是现在我怎样才能一一传递16所有人的动态价值employeeId。
用途outer/cross apply:
outer/cross apply
select * from Employee as E cross apply dbo.[StateFixedTaxesCalculation](3020, E.EmployeeId, 1, 1006) as TC
如果仍然需要按进行过滤TC.EmployeeId = E.EmployeeId,则可以使用子查询来执行此操作:
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