SQL

SQL Server Functions

Function is a set of SQL Statements that perform the operations

Built-in scalar functions takes input of a single value and return a single value
Built-in aggregate functions acts on multiple values and return a single value
User defined scalar function returns a single value of any data type
Inline table-valued function returns a table variable derived from one SQL statement
Multi-statement table-valued function returns a table variable derived from multiple SQL statements
Window functions operate aggregate or ranking functions on a set of rows

Create Scalar function:
Create function fn()
Returns int
As
Begin
Return 3
End
Call function:
Select dbo.fn()
Output:
3
Create table-valued function:
Create function tfn()
Returns table
As
Return Select ProductID from Product
Call table-valued function:
Select * from dbo.tfn()
Output:
1
2
3
4