This blog will explain one of the most important question in interview?
Is How to Join Table Valued Function with Table?
For Ex
- Create table Emp asAnd Insert Record into Emp table as
- CREATE TABLE [dbo].[Emp](
- [ID] [int] IDENTITY(1,1) NOT NULL,
- [Name] [varchar](50) NULL,
- [City] [varchar](50) NULL,
- CONSTRAINT [PK_Emp] PRIMARY KEY CLUSTERED
- (
- [ID] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
- GO

- Create Table value function asThen we can join these table value function and table with in the help of "Cross Apply" as
- GO
- -- =============================================
- -- Author: <Author:- Vishvajeet>
- -- Create date: <Create:- 23/11/2014>
- -- Description: <Description:- Fn_Select Employee Salary>
- -- =============================================
- Create FUNCTION [dbo].[fn_Salary]
- (
- @id Int
- )
- RETURNS TABLE
- AS
- RETURN
- (
- SELECT Salary from Salary where ID=@id
- )
- select e.ID,e.Name,e.City,x.Salary from Emp e left join
- (
- select ID,Name,Salary from Emp cross apply [dbo].fn_Salary(ID)
- )x on x.ID=e.ID
And show Result as


Vishvajeet PawarPosted Nov 24, 2014, 9:04 AM
Yes joginder Sir..your right but such kind of question ask on interview..?
Joginder BangerPosted Nov 24, 2014, 7:30 AM
hello Vishvajeet Pawar sir , we can do it without function so why lengthy make this program. sir if we are passed table in parameter. Good work sir....Go ahead.. enjoy with Respective C-sharpcorner