Overview

What are the Microsoft SQL database functions?

CREATE FUNCTION (Transact-SQL) - SQL Server

IF OBJECT_ID (N'dbo.FN_MyFunctionName') IS NOT NULL
   DROP FUNCTION dbo.FN_MyFunctionName
GO

CREATE FUNCTION MyFunctionName 
(
	@p1 INT, 
	@p2 CHAR(1))
RETURNS TABLE
AS
RETURN SELECT @p1 AS 'Number', @p2 AS 'Character'
GO

-- Testing:
SELECT * FROM dbo.MyFunctionName(5, 'a');
IF OBJECT_ID (N'dbo.FN_MyFunctionName') IS NOT NULL
   DROP FUNCTION dbo.FN_MyFunctionName
GO

CREATE FUNCTION FN_FunctionName (@p1 INT)
RETURNS INT
AS
BEGIN
	RETURN (@p1 + 10);
END
GO

-- Testing:
SELECT dbo.FN_FunctionName(5) AS Test;

UDF Definition Rules

UDF Drawbacks

Scalar Functions