User Defined Function example in SQL Server 2008

InfoPath alternatives for form designing SharePoint

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

You can also check some useful posts like: Get all user defined tables in SQL Server 2008, view in sql server 2008 and 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
as
begin

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

return @result

end

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:
– Function returns only single value.

– Function accepts only input parameters.

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

– Function doesn’t support Exception handling.

Similar SharePoint 2013 Tutorials


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 SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply