私は何かをしたい
select * from tvfHello(@param) where @param in (Select ID from Users)
私は何かをしたい
select * from tvfHello(@param) where @param in (Select ID from Users)
これを実現するにはCROSS APPLYを使用する必要があります
select
f.*
from
users u
cross apply dbo.tvfHello(u.ID) f
以下は、AdventureWorks データベースで機能します。
CREATE FUNCTION dbo.EmployeeByID(@employeeID int)
RETURNS TABLE
AS RETURN
(
SELECT * FROM HumanResources.Employee WHERE EmployeeID = @employeeID
)
GO
DECLARE @employeeId int
set @employeeId=10
select * from
EmployeeById(@employeeId)
WHERE @EmployeeId in (SELECT EmployeeId FROM HumanResources.Employee)
クリストフの専門知識に基づいて、たとえば次のように複数の値を取得しようとしている場合は、このサンプルを更新しました。
select *
from HumanResources.Employee e
CROSS APPLY EmployeeById(e.EmployeeId)
WHERE e.EmployeeId in (5,6,7,8)
関数の前に常にスキーマ (通常は dbo) を付ける必要があることを除いて、それは私には問題ないように見えます。したがって、クエリは次のようになります。
SELECT * FROM dbo.tvfHello(@param) WHERE @param IN (SELECT ID FROM Users)