Multistatement table valued function in SqlServer

Syedshakeer
Posted by Syedshakeer under Sql Server category on | Views : 3045
alter function function_stud1()
RETURNS @table TABLE
(id int,
eng int,
comp int,total int,grade char
)
AS
begin
declare @id as integer
declare @eng as integer
declare @comp as integer
declare @total as integer
set @id=344
set @eng=84
set @comp=89

insert into @table(id,eng,comp) values(@id,@eng,@comp)
set @total=@eng+@comp
update @table set total=@total, grade=CASE
when (@total) > 160 then 'A'
when (@total) > 120 and @total<160 then 'B'
when (@total) > 80 and @total<120 then 'C' end where id=@id
--select * from stud
RETURN
end


calling the function with select statement.
select * from function_stud1()

Comments or Responses

Login to post response