Transact-SQL provides many functions that return information. Functions take input parameters and return values that can be used in expressions. The Transact-SQL programming language provides three types of functions, aggregate, scalar, and rowset.
Aggregate Functions
Aggregate functions operate on a collection of values but return a single, summarizing value.
Example 1
This example determines the average of the UnitPrice column for all products in the Products table.
SELECT AVG(UnitPrice) FROM Products
Result
| Products | ||||||
|---|---|---|---|---|---|---|
28.8663 | ||||||
(1 row(s) affected) | ||||||
| Scalar Functions Scalar functions operate on a single value and then return a single value. You can use these functions wherever an expression is valid. You can group scalar functions into the categories in the following table.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Example 2 This metadata function example returns the name of the database currently in use.SELECT DB_NAME() AS 'database' Result
Rowset Functions Rowset functions can be used like table references in a Transact-SQL statement. Example 3 This example performs a distributed query to retrieve information from the EMP table. SELECT * FROM OPENQUERY(OracleSvr, 'SELECT ENAME, EMPNO FROM SCOTT.EMP') | |||||||||||||||||||||||||||||||||||||||||||||||||
0 komentar:
Poskan Komentar