TSQL-Part2 : TSQL-Part2 Filtering data from Sql Server 2005 using simple 'Where Clause'
By
Nitin Sharma
The 'Where Clause' : The 'Where Clause' SELECT Statement, Selects Records from table(s).
'Where Clause' is used to filter data being retrieved by a Select Statement.
'Where Clause' uses 'predicates' or 'conditions' to restrict data being retrieved.
Predicates use Relational, Boolean and Special Operators to define a condition.
Ex: Select * from customers where city='London'
The 'Where Clause' (Cont..) : The 'Where Clause' (Cont..)
The 'Where Clause' (Cont..) : The 'Where Clause' (Cont..) Note that string field values in a 'Where Clause' are written inside single quotes for example 'London'.
By default in SQL Server the where clauses are case-insensitive when it comes to searching data so City='London' and City='LONDON' will yield the same results.
Where clause uses relation operators =,>,<,>=,<=,<> in the predicates.
The 'Where Clause' (Cont..) : The 'Where Clause' (Cont..)
The 'Where Clause' (Cont..) : The 'Where Clause' (Cont..) You may also combine predicates in a 'Where Clause' by Boolean operators (AND, OR and NOT).
Ex: Select * from products where unitprice>10 and unitprice<20
'NOT' is a special boolean operator which negates a condition for example Select * from products where NOT unitprice>10
The 'Where Clause' (Cont..) : The 'Where Clause' (Cont..) Note: You can add comments in a TSQL window by enclosing between /* and */ characters. This way the comments can span multiple lines.
The 'Where Clause' (Cont..) : The 'Where Clause' (Cont..) Note: You can add single line comments in a TSQL window by starting them with -- characters.