User-Defined Function Samples
These four Transact-SQL samples show how to use user-defined functions. Earlier versions of Microsoft® SQL Server™ supplied only built-in functions defined as part of the Transact-SQL language. Built-in functions operate as defined in the Transact-SQL Reference and cannot be modified. Microsoft® SQL Server™ 2000 introduces user-defined functions that allow you to define and modify your own Transact-SQL functions.
|Udf_CustNamesInRegion||Transact-SQL sample. This script creates an in-line user-defined function in the Northwind database to view customer information for specific regions from the Customers table.|
|Udf_FindReports||Transact-SQL sample. This script creates a function that queries the Employees table in the Northwind database and shows all direct and indirect reports.|
|Udf_LargeFreight||Transact-SQL sample. This script creates a user-defined function that queries the Shippers and Orders tables in the Northwind database and returns orders with freight greater than a certain value.|
|Udf_MyDate||Transact-SQL sample. This script creates a single function that changes the format in which the date is returned. The script can be used on any table in the database.|
To install the samples during SQL Server installation
- On the Setup Type page, select Custom.
- On the Select Components page, under Components, select Code Samples.
Samples are installed as a self-extracting file. To extract the samples, double-click Unzip_misc.exe, located at C:\Program Files\Microsoft SQL Server\80\Tools\Devtools\Samples\Misc.
C:\Program Files\Microsoft SQL Server\80\Tools\Devtools\Samples\Misc\Udf
Running the Samples
Instructions are included in Userdefinedfunc.doc, located at
C:\Program Files\Microsoft SQL Server\80\Tools\Devtools\Samples\Misc\Udf.