Transact-SQL Reference

Functions

The Transact-SQL programming language provides three types of functions:

Function Determinism

SQL Server 2000 built-in functions are either deterministic or nondeterministic. Functions are deterministic when they always return the same result any time they are called with a specific set of input values. Functions are nondeterministic when they could return different results each time they are called, even with the same specific set of input values.

The determinism of functions dictate whether they can be used in indexed computed columns and indexed views. Index scans must always produce consistent results. Thus, only deterministic functions can be used to define computed columns and views that are to be indexed.

Configuration, cursor, meta data, security, and system statistical functions are nondeterministic. In addition, the following built-in functions are also always nondeterministic:

@@ERROR FORMATMESSAGE NEWID
@@IDENTITY GETANSINULL PERMISSIONS
@@ROWCOUNT GETDATE SESSION_USER
@@TRANCOUNT HOST_ID STATS_DATE
APP_NAME HOST_NAME SYSTEM_USER
CURRENT_TIMESTAMP IDENT_INCR TEXTPTR
CURRENT_USER IDENT_SEED TEXTVALID
DATENAME IDENTITY USER_NAME

Function Collation

Functions that take a character string input and return a character string output use the collation of the input string for the output.

Functions that take non-character inputs and return a character string use the default collation of the current database for the output.

Functions that take multiple character string inputs and return a character string use the rules of collation precedence to set the collation of the output string. For more information, see Collation Precedence.

See Also

CREATE FUNCTION

Deterministic and Nondeterministic Functions

User-defined Functions