C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






How to write a Function in SQL Server


Posted Date: 17 Sep 2008    Resource Type: Code Snippets    Category: SQL

Posted By: Bunty       Member Level: Diamond
Rating:     Points: 10



This code shows how to write a function in sql server
A function which takes Empno and calculate Total and Anuual Salary and returns them

Create Function get_EmpData(@empno int)
Returns @MyTable Table(Total Money,Annual Money)
As
Begin
Declare @Sal Money,@Comm Money
Declare @TSal Money,@ASal Money
Select @Sal=sal, @Comm=comm from emp
where empno@empno

Set @TSal = @Sal + IsNull(@Comm,0)
Set @ASal = (@Sal + IsNull(@Comm,0))*12
Inset into @MyTable Values(@TSal,@ASal)
Return

End

Calling the above function

Select * from get_EmpData(1005)

Regards
S.S.Bajoria




Responses

Author: umang    29 Sep 2008Member Level: Bronze   Points : 0
This coding is very useful.by this way a programmer get much a help.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Function in SQL Server  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Using SYSOBJECTS : Get Table Schema
Previous Resource: Cascading deletes using trigger
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

audio conferencing services

Contact Us    Privacy Policy    Terms Of Use