Retrieving Data from a Function

You retrieve data from a function by using a SELECT statement. Functions can be used in:

  • SELECT list

  • WHERE clause

  • Expression

  • CHECK or DEFAULT constraint

  • FROM clause with the CROSS/OUTER APPLY function

How a function is used can have a dramatic impact on the performance of the queries that you execute.

A function in the SELECT list is used to calculate an aggregate or perform a computation on one or more columns from the tables in the FROM clause.

A function in the WHERE clause is used to restrict a result set based on the results of the function. You should not create queries that utilize a function in the WHERE clause, because the function has to be executed once for each row in the result set in order to determine if ...

Get Microsoft® SQL Server® 2008 Step by Step now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.