Thumb

Introduction to function

9/14/2020 7:21:12 AM

Introduction to function: SQL have some predefine function like count. This function returns a int value but also we create our won functions. Our created function called user define function. This function looks like stored procedures but some deferent working process stored procedures and function. Like we use the function after where clause but we can’t use the   stored procedures. Now given bellow the example code:

CREATE FUNCTION empSalary()
RETURNS float
AS 
BEGIN
    RETURN (select Salary.Salary from Salary where Salary.Id=3)
END;
select dbo.empSalary()

In this function create by create keyword and structure look like stored procedures then the function returns an int value. We execute the function by select statement.