--question 3
create function movie_income(@mtitle char(20))
returns real
as
begin
--function body
declare @total_income real
select @total_income=sum(ticketPrice*spectators)
from Show s
where s.movieTitle = @mtitle
return @total_income
end
declare @income real
exec @income=movie_income 'Spider-man'
print @income
--question 4
create function remain_seats(@sid int)
returns int
as
begin
declare @seats int
select @seats=t.capacity-s.spectators
from Theater t, Show s
where t.theaterName=s.theaterName
and s.showId=@sid
return @seats
end
declare @no_of_seats int
exec @no_of_seats=remain_seats 2
print @no_of_seats
Негізгі бет DMS sql programming - creating functions tutorial 2
Пікірлер: 11