views:

21

answers:

1

I thought that must be obvious but I can't figure it out.

Say there is a table tblData with a column ID and a table-valued-function (_tvf) that takes an ID as parameter. I need the results for all ID's in tblData.

But:

SELECT * FROM tblData data 
INNER JOIN dbo._tvf(data.ID) AS tvfData
   ON data.ID = tvfData.ID

gives me an error: The multi-part identifier "data.ID" could not be bound

What is the correct way to pass all ID's to this TVF and concat the results?

Thanks

+3  A: 

I think you might need to use CROSS APPLY instead of an inner join here:

SELECT * 
FROM dbo.tblData data 
CROSS APPLY dbo._tvf(data.ID) AS tvfData

This will call the TVF function for each data.ID of the base table and join the results to the base table's columns.

See ressources here:

marc_s
That works, thanks :)
Tim Schmelter
Unfortunately i'm getting a "The maximum recursion 100 has been exhausted before statement completion" Error. because this is another question, maybe you could help me there too. http://stackoverflow.com/questions/3986240/multi-part-identifier-could-not-be-bound
Tim Schmelter
I had to apply an OPTION (MAXRECURSION 0) to the end of the Selct-Statement that calls the ITVF. Now it works, thanks again.
Tim Schmelter