- A function must have a name and a function name can never start with a special character such as @, $, #, and so on.
- Functions only work with select statements.
- Functions can be used anywhere in SQL, like AVG, COUNT, SUM, MIN, DATE and so on with select statements.
- Functions compile every time.
- Functions must return a value or result.
- Functions only work with input parameters.
- Try and catch statements are not used in functions.
SQL Server support two types of user defined functions:
- Table Valued Functions
- Scalar Valued Functions
Table Valued Functions
In this type of function, we select a table data using a user created function.
Example:
- Create function Fun_EmployeeInformation()
- returns table
- as
- return(select * from Employee )
Syntax:
- create function fun_JoinEmpColumnInfo
- (
- @EmpContact nchar(15),
- @EmpEmail nvarchar(50),
- @EmpCity varchar(30)
- )
- returns nvarchar(100)
- as
- begin return(select @EmpContact+ ' ' +@EmpEmail + ' ' + @EmpCity)
- end
No comments:
Post a Comment