Sunday, 27 August 2017

Creating Function in SQL Server

Creating Function in SQL Server

create table emp_salary(id int primary key identity(1,1), current_salary bigint )

insert into emp_salary(current_salary) values(5000)
insert into emp_salary(current_salary) values(6000)
insert into emp_salary(current_salary) values(7000)
insert into emp_salary(current_salary) values(8000)
insert into emp_salary(current_salary) values(8000)
insert into emp_salary(current_salary) values(6000)

Creating a Function for calculate next_month_salary (current_salary_2000)

create function f2(@sal int)
returns int
as
begin
declare @next_month_salary int
set @next_month_salary=@sal+2000
return @next_month_salary
end
Calling Current Month Salary
select Current_salary from emp_salary

Calling function in SQL Server
 select current_salary,dbo.f2(current_salary) as Next_month_salary from emp_salary

No comments:

Post a Comment

React Hooks - custom Hook

  v CustomHook Ø React allows us to create our own hook which is known as custom hook. Example – 1 localStorage Demo Step-1 Create ...