Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > SQL SERVER (TECHNET) > sql server 2000
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 25th July 07:28
wendy elizabethgw6zr
External User
 
Posts: 1
Default sql server 2000



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!
  Reply With Quote


  sponsored links


2 25th July 07:29
hari prasad
External User
 
Posts: 1
Default sql server 2000



Hi,

See Functions DATEPART and CONVERT in books online.

Thanks
Hari
SQL Server MVP
  Reply With Quote
3 25th July 07:30
david portas
External User
 
Posts: 1
Default sql server 2000


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
--
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666