O'Reilly logo

Microsoft® SQL Server 2008 R2 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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–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:

image

The syntax for the CREATE FUNCTION ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required