0% found this document useful (0 votes)
50 views3 pages

Functions Sample

Uploaded by

api-3766129
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views3 pages

Functions Sample

Uploaded by

api-3766129
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

--1)

Create Function Pf_fun


(
@Sal Money

)Returns Money
As
Begin
Declare @pf Money
Set @pf=@sal*0.12
Return @pf
End

go
select dbo.Pf_fun(2000)
--2)

create function Netsal


(
@sal money

)returns money
as
begin
declare @Netsal money
set @Netsal=@sal-(@sal*0.12)
return @Netsal
end
go
select dbo.Netsal(2000)
--3)
Create function a_plus_b_square
(
@a float,
@b float
)returns float
As
Begin
Declare @result float
set @result=(@a*@a)+(@b*@b)+(2*@a*@b)
return @result
end
select dbo.a_plus_b_square(2,3)

--4) Using table emp


--select * from emp
select Empid,EmpName,Deptno,(dbo.Netsal(salary))[Netsalary] from emp
--5)

Create Function Area_of_circle


(
@r float
)returns float
As
Begin
Declare @Area float
Set @Area=(22/7)*@r*@r
return @Area
end
select dbo.Area_of_circle(2)
--Doubt-Here the answer is 12.57 but the above fun. shown only 12.0 why?

--6)
create function Greatest_of_3_numbers
(
@a float,
@b float,
@c float
)returns float
As
Begin
Declare @Big float
if @a>@b and @a>@c
set @big=@a

else
if @b>@c
set @big=@b
else
set @big=@c
return @big
end
select dbo.Greatest_of_3_numbers(300,2000,40)
--7)
create function CubicVolume
(
@CubeLength decimal(4,1),
@Cubewidth decimal(4,1),
@cubeHeight decimal(4,1)
)
RETURNS decimal(12,3)
As
begin
Declare @Volume decimal(12,3)
set @Volume=@CubeLength*@CubeWidth*@CubeHeight
Return @Volume
end
--select dbo.CubicVolume(2,3,4)
go
---Or
create function CubeVolume
(
@Length float,
@width float,
@Height float
)
RETURNS float
As
begin
Declare @Volume float
set @Volume=@Length*@Width*@Height
Return @Volume
end
--select dbo.CubeVolume(2,3,4)
go
--8)
--select * from emp

--8)
select Empid,EmpName, dbo.Pf_fun(salary)Pf from emp
where EmpName like 'N%'
--9)
select Empid,EmpName,Deptno,dbo.Pf_fun(salary)Pf,
(dbo.Netsal(salary))[Netsalary] from emp
where salary<4000

You might also like