Creating User-Defined Functions

You create T-SQL functions by using T-SQL statements. You can enter the T-SQL code in sqlcmd, SSMS, or any other third-party query tool that allows you to enter ad hoc T-SQL code. The following sections first show the basic syntax for creating functions and then show how you can create functions by using the features of SSMS.

Creating T-SQL Functions

User-defined functions can accept 0 to 2,100 input parameters but can return only a single result: either a single scalar value or table result set.

The T-SQL syntax for the CREATE FUNCTION command for scalar functions is as follows:

CREATE FUNCTION [ schema_name. ] function_name    ( [ { @parameter_name [AS] [ schema_name.]scalar_datatype ...

Get Microsoft SQL Server 2014 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.