A function is a sequence of statement that accepts values as input, processing them and provide result as output. A function must have a unique name and a function name can not starts with special character like- @, #, $, … and so on.
Types of Function:
There are generally two types of function used in SQL server.
1- Predefined function.
2- User defined function.
Predefined Function:
This function is also called system function which are created automatically by the system.
User Defined Function:
A user defined function is created by developer. It is create for a specific task according to needs. The main advantage of this function is that we are not limited just like predefined function. We can write our own function for out need or simplify the SQL code. The return type of a function is a scalar values or a table.
A SQL function is must return a value and it works with input parameter. Function is compile every time, try and catch statement are not used in function.
Example:
Execute of the above function,
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
SQL Function:
A function is a sequence of statement that accepts values as input, processing them and provide result as output. A function must have a unique name and a function name can not starts with special character like- @, #, $, … and so on.
Types of Function:
There are generally two types of function used in SQL server.
1- Predefined function.
2- User defined function.
Predefined Function:
This function is also called system function which are created automatically by the system.
User Defined Function:
A user defined function is created by developer. It is create for a specific task according to needs. The main advantage of this function is that we are not limited just like predefined function. We can write our own function for out need or simplify the SQL code. The return type of a function is a scalar values or a table.
A SQL function is must return a value and it works with input parameter. Function is compile every time, try and catch statement are not used in function.
Example:
Execute of the above function,