What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 3683 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > SQL Server > Multistatement table valued function in SqlServer ...
Syedshakeer

Multistatement table valued function in SqlServer

 Code Snippet posted by: Syedshakeer | Posted on: 3/31/2010 | Category: SQL Server Codes | Views: 1951 | Status: [Member] | Alert Moderator   


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()


Syed Shakeer Hussain
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 9:14:50 PM