Transact-SQL Functions

 


Transact-SQL (T-SQL) functions are subprograms that encapsulate a sequence of T-SQL statements. T-SQL functions can return a single scalar value, a single row, or multiple rows.

There are two types of T-SQL functions:

·        Scalar functions: return a single scalar value, such as an integer, a string, or a date/time value.

·        Table-valued functions: return a table, allowing multiple rows to be returned and processed like a physical table.

Some common T-SQL functions include:

·        Aggregate functions: COUNT, SUM, AVG, MIN, MAX, etc.

·        Date and time functions: GETDATE, DATEADD, DATEDIFF, etc.

·        String functions: LEN, SUBSTRING, CHARINDEX, etc.

·        Conversion functions: CAST, CONVERT, etc.

System functions: @@ROWCOUNT, @@IDENTITY, @@ERROR, etc.

Functions can be used in T-SQL statements to manipulate data and simplify complex calculations.