Inline Table Functions — Complete Guide
Inline Table Functions — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of SQL Server Tutorial on Toolliyo Academy.
On this page
SQL Server Tutorial · Lesson 44 of 100
Inline Table Functions
SQL basics ✓ → Queries → Advanced
Queries · 2 — JOINs · ~6 min · SQL — Stored Procedures & Functions
What is this?
An inline table-valued function (iTVF) returns a table via a single RETURN SELECT — the optimizer can expand it like a view with parameters.
Why should you care?
Parameterized reusable queries that still optimize well — better than many scalar UDFs.
See it live — copy this example
Run in SQL Server Management Studio (SSMS) or Azure Data Studio.
USE DataVerse;
CREATE OR ALTER FUNCTION dbo.fn_OrdersForCity(@City NVARCHAR(50))
RETURNS TABLE
AS
RETURN
(
SELECT OrderId, CustomerId, Amount, OrderDate
FROM dbo.Orders
WHERE City = @City
);
GO
SELECT f.OrderId, f.Amount, c.FullName
FROM dbo.fn_OrdersForCity(N'Mumbai') AS f
LEFT JOIN dbo.Customers AS c ON c.CustomerId = f.CustomerId;
What happened?
- The function is a parameterized SELECT.
- Callers join it like a table.
- No BEGIN/END multi-statement body — that keeps it inline.
Practice next
- Create fn_OrdersForCity and query Mumbai.
- Join to Customers as shown.
- Check the plan — should look like a normal join + filter.
- Add @MinAmount parameter to the function.
- CROSS APPLY the function from Customers.
Remember
iTVF = parameterized view-like SELECT. Optimizer-friendly reuse. Single RETURN SELECT only.
City ops reusable set
Several DataVerse reports call fn_OrdersForCity.
Outcome: One definition, consistent city filters.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!