29.SQL Server - Table Valued Functions (TVF) | Inline Table Valued Functions

Опубликовано: 01 Октябрь 2024
на канале: Tech2BI
74
6

In this class we discuss about Inline Table Valued functions:

SQL Table-Valued Function (TVF) is a user-defined function that returns a table as a result set. Unlike scalar functions that return a single value, a TVF can be used to encapsulate a complex logic that generates and returns a table of data. TVFs are particularly useful when you need to perform a set of operations on a dataset and return the result as a table, which can then be used in a query like a regular table or joined with other tables.

-- Table Valued Functions

-- TVFS we can use used after FROM clause in the SELECT statements.
-- Tvfs can be categeorized into two types
--i. Inline
-ii. Multi statement table valued

-- Synatx for the Inline Table Valued Funtcions

-- CREATE
-- FUNCTION FN_NAME (@Para1 DATATYPE))
-- RETURNS TABLE
-- AS
-- RETURN ( SELECT COL1,COL2 .... FROM TABLE WHERE COL1=@Para1)