Summary


Although you haven't seen a lot of complexity in this introduction to the SELECT statement and its fundamental nuances, it's a very powerful tool. As you continue to build more complex statements, the SELECT statement will be center stage. This chapter started by explaining selecting all rows using the asterisk (*) to return values for all available columns in a table and then moved on to specify selected columns. It is more efficient to return only the columns needed. This is especially the case when standard queries will be called routinely by software code, a report, or an application component. You learned how columns can be aliased to either rename a column or return a new column from a literal value, calculation, or expression based on multiple column values.

Filtering rows is the function of the WHERE clause, using logical comparisons. Values may be equal to, less than, greater than, or the opposite of any of the above by using the NOT operator. Character data types can also be compared using the LIKE operator to perform partial matching, wildcard, and pattern matching. Using Null is the accepted method to indicate that a column value has not been set — and testing for Null gives you an exact method to test for this condition. When combining comparison operators, it's often necessary to indicate the order of operations using parentheses. Not only does this ensure that operations are performed in the appropriate order, but it also makes queries much easier to read and maintain.

Rows can be sorted on any number of columns and can be placed in ascending or descending order. Finally, this chapter discussed the use of the TOP keyword, used to truncate a result set either by a specific number of rows or by a percentage of the entire result set.




Beginning Transact-SQL with SQL Server 2000 and 2005
Beginning Transact-SQL With SQL Server 2000 and 2005
ISBN: 076457955X
EAN: 2147483647
Year: 2006
Pages: 131
Authors: Paul Turley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net