Hi! In this tutorial we will learn how to add two numbers in sql server by function and how we can use the function. We must execute the code below and get succesful message than we can use that function we want.
1 2 3 4 5 6 7 8 |
Create function fn_sum(@p1 int,@p2 int) returns int as Begin Declare @result int Set @result = @p1 + @p2 Return @result End |
Solution 2
1 2 3 4 5 6 |
Create function fn_sum(@p1 int,@p2 int) returns int as Begin Return @p1 + @p2 End |
The function’s usage types;
The basic usage:
1 |
Select dbo.fn_sum(23,34) |
Usage in a Query;
1 |
Select *,dbo.fn_sum(pageCount,point) as Result from books |
CLICK HERE TO SEE MORE EXAMPLE ABOUT SCALAR VALUED FUNCTIONS