CHAPTER 2
Single-Table Queries
79
You get the following output.
-----------------------
1900-01-01 12:30:15.123
Suppose you have a table with a column called tm of a DATETIME data type and you store all val-
ues by using the base date. Again, this could be enforced with a CHECK constraint. To return all rows
for which the time value is 12:30:15.123, you use the filter WHERE tm = ‘12:30:15.123’. Because you
did not specify a date component, SQL Server assumes that the date is the base date when it implic-
itly converts the character string to a DATETIME data type.
If you want to work only with dates or only with times, but the input values you get include both
date and time components, you need to apply some manipulation on the input values to “zero” the
irrelevant part. That is, set the time component to midnight if you want to work only with dates, and
set the date component to the base date if you want to work only with times. I’ll explain how you can
achieve this shortly, in the “Date and Time Functions” section.
Do'stlaringiz bilan baham: |