I am trying to make a remote call to a function over a linked server which is not allowed directly ([linkedserver].[database].[dbo].fnGet()] so I'm having to use OPENQUERY to perform that function call. This works great when I hard code in a value as my function parameter, but I need this function call to be dynamic and use a column from a joined (via CROSS APPLY) table.
SELECT
sc.FirstName
,sc.LastName
,sc.StudentId
,p.EnrollId
FROM
StudentClasses AS sc
CROSS APPLY
(
SELECT * FROM OPENQUERY
(
[LinkedServer],'SELECT database.dbo.fnGet(sc.StudentId) AS EnrollId'
)
)AS p
unfortunately it keeps failing saying that the multi-part identifier 'sc.StudentId' could not be bound.
I've found a few resources that show how to correct this for local function calls, but nothing for a remote call with OPENQUERY.
Any help would be greatly appreciated.