Database Reference
In-Depth Information
You can format dates and times and alternative functions for extracting and converting them in
various ways. Dates and times can also be added and subtracted and incremented and decremented.
How this is done is DBMS-specific, though all DBMSs comply to a reasonable extent with the SQL
standard in how they do it. Whatever DBMS you use, you'll find that dates and times are the most
complicated data types to employ. But, in all cases, you'll find that functions (sometimes a richer set of
them than in T-SQL) are the basic tools for working with dates and times.
Tip When providing date and time input, character string values are typically expected; for example, 1/26/2012
would be the appropriate way to specify the value for a column holding the current date from the example.
However, DBMSs store dates and times in system-specific encodings. When you use date and time data, read the
SQL manual for your database carefully to see how to best handle it.
List Operator
IN is SQL Server's list operator; it allows you to specify the list of choices you want to base your condition
upon. For example, you want to extract all the cities of your desired list. SQL Server offers its negation as
well, NOT IN , so you can choose the values that you don't want to be included in your result set.
Try It: Using the IN Operator
Open a New Query window in SQL Server Management Studio. Enter the following query, and click
Execute. You should see the results shown in Figure 5-15.
select AddressID, AddressLine1, City
from Person.Address
where City in ('Bellevue', 'Redmond', 'Seattle')
 
Search WWH ::




Custom Search