User Defined Function example in SQL Server 2008

In this post, we will check one user-defined function in SQL Server 2008.

New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features

You can also check some useful posts like:

Get all user-defined tables in SQL Server 2008

view in sql server 2008

Difference between primary key and foreign key in SQL server.

User-defined functions can be created by users.

Below is a function that will take one input parameter and also returns one integer value.

Here it will take the empid and returns the contact number for the particular empid.

Create function EmployeeContact(@Empid int)
returns int

declare @result int
select @result=EmloyeeDetail.ContactNo from EmloyeeDetail where employee detail.Empid=@Empid

return @result


You can call the function like below
Select dbo.EmployeeContact(1) as ContactNumber from EmloyeeDetail

This will return the contact number of empid =1.

Here are some points to remember about functions:
– The function returns only a single value.

– The function accepts only input parameters.

– The function can not be used to Insert, Update, Delete data in database table.

– The function doesn’t support Exception handling.

Check out Best Alternative to InfoPath -> Try Now


(Installation & Features)

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site

View all posts by Bijay Kumar →