Call TVF on every record of a table and concat results

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.

  • Count based on condition in SQL Server
  • SQL Server automatically strips trailing whitespace
  • Joining/Appending different tables together in Microsoft sql server
  • calling an api from sql server stored-procedure
  • how to deal with “remapping can only be done for users that were mapped to Windows or SQL logins”
  • Assemblies in SQL Server keep unloading and loading again periodically
  • 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?


  • Using SSIS, How do I find the cities with the largest population?
  • Nested select statement in SQL Server
  • “Index was outside the bounds of the array” while Compare SQL schema by SQL compare tool
  • SQL SERVER: Altering service broker stored procedures
  • Export Image column from SQL Server 2000 using BCP
  • How to speed up reading large amounts of data in SQL Server and C#
  • One Solution collect form web for “Call TVF on every record of a table and concat results”

    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:

    • Using CROSS APPLY in SQL Server
    • Understanding APPLY clause in SQL Server
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.