Groups | Blog | Home
all groups > sql server mseq > july 2005 >

sql server mseq : sql server 2000


Wendy Elizabeth
7/14/2005 8:46:13 AM
I just started to work with sql server 2000. I want to write a query

against "datetime" columns in the sql server 2000 database. I am to be

able to do the following with the sql server 2000 "datetime" columns:

1. Be able to access the date portion only.
2. Be able to access the time portion only.
3. Be able to access only a portion of the date like the month and/or

year only.
4. Be able to access only a portion of the time like the milliseconds

and/or the minutes.

What kind of query statements would I need to write, to be able to

access only a portion of "datetime" columns?

Thanks!
Hari Prasad
7/15/2005 12:00:00 AM
Hi,

See Functions DATEPART and CONVERT in books online.

Thanks
Hari
SQL Server MVP

"Wendy Elizabeth" <WendyElizabeth@discussions.microsoft.com> wrote in
message news:2098B955-D0AF-4C4D-A7FC-930EFC2CB6BC@microsoft.com...
[quoted text, click to view]

David Portas
7/17/2005 10:56:41 PM
For 1 and 3, use date ranges wherever possible so as to avoid complex
expressions and type conversions and to help maximize the benefit of any
indexes. Examples:

One day:

SELECT *
FROM YourTable
WHERE date_col >= '20050717'
AND date_col < '20050718'

One month:

SELECT *
FROM YourTable
WHERE date_col >= '20050701'
AND date_col < '20050801'

For 2 and 4, take a look at the DATEPART function in Books Online.

--
David Portas
SQL Server MVP
--

AddThis Social Bookmark Button