SQL functions
This section will be dedicated to the use of functions. We will see what the most important built-in functions of SQL Server are and how to use them, as well as declare, execute and manipulate our own user functions: both scalar functions and table functions
-
Built-in functions in SQL
A function can be defined as a set of instructions that performs a certain task automatically. Built-in functions are those system-specific functions, already defined by SQL-Server
-
Built-in scalar functions in SQL
Scalar functions operate on one value and return another. There are different types of scalar functions.
-
User-defined Functions in SQL
A function can be defined as a set of instructions that performs a certain task automatically. User-defined functions are those for defining your own custom functionality
-
Scalar functions in SQL
Scalar functions return a single scalar value whose data type will be defined in the RETURN clause
-
Table functions in SQL
Table functions return a result set in the form of a table. We will review the statements to create, execute, modify and eliminate user functions with examples
What you will learn in this section
A function takes values and returns a result. SQL Server ships with hundreds of them and also lets you write your own.
- Built-in functions: which families exist and what each one is for.
- Built-in scalar functions: text, dates, numbers and type conversion, with examples of each.
- User-defined functions: why and when to create your own.
- Scalar functions: your own functions that return a single value.
- Table-valued functions: your own functions that return a table and can be used in
FROMas if they were one.
If you have not yet covered variables and BEGIN...END, it is worth reviewing them before writing your own functions.