Just another day I received following question and I find it very interesting. I decided to try it out on SQL Server 2016’s new WideWorldImporters database. The question was – “How to Join a Table Valued Function with a Database Table?” This is indeed very interesting as this particular feature was introduced in SQL Server 2008, so what you will see in this blog post applies to every version of SQL Server after SQL Server 2008.
In database WideWorldImporters we have a table valued function – [Application].[DetermineCustomerAccess], which accepts city id as an input and returns us result if that particular city have accessed enabled or not. We will join this to Sales.Customers table which also have a column city. Now we want to know if the customer city has access enabled or not. To find out we have to join a table valued function with our customer table. Here is the syntax to join table valued function to a table. We will apply CROSS APPLY to connect function and table.
USE WideWorldImporters GO SELECT c.CustomerName, a.AccessResult FROM Sales.Customers c CROSS APPLY [Application].[DetermineCustomerAccess] (DeliveryCityID) a GO
Let me know if you have any question in the comment area.
Reference: Pinal Dave (https://blog.sqlauthority.com)