Completely Free .NET word API

Resources » Code Snippets » SQL

How to write a Function in SQL Server

Updated: Category: SQL
Author: Member Level: GoldPoints: 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)
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)


Calling the above function

Select * from get_EmpData(1005)


Did you like this resource? Share it with your friends and show your love!

Responses to "How to write a Function in SQL Server"
Author: umang  29 Sep 2008   Member Level: Bronze   Points : 0
This coding is very this way a programmer get much a help.


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India