Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 is it right?

Author  Topic 

hong_ma
Starting Member

37 Posts

Posted - 2006-02-28 : 14:19:59
There are three fields ID(int), historyID(int), datatime(smallDate) in the report table
I would like to get data records which is before the datatime 60 days and after the datatime 30 days
from the report table.
my query looks like that

select ID, historyID, datatime
from report
where datatime between (datetime -60) and (datatime +30)


Use DATEADD ( dd, 60, @datetime) to change (datetime -60) and (datatime +30) to change to smalldate type
is it right? Thanks

JoeNak
Constraint Violating Yak Guru

292 Posts

Posted - 2006-02-28 : 15:01:40
I think you mean (not sure)
WHERE datatime BETWEEN DATEADD(dd, -60, @datetime) AND DATEADD(dd, 30, @datetime)

The smalldatetime datatype is just a smaller date range than datetime.

If you're looking to strip the time off take a look here:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62354
Go to Top of Page

hong_ma
Starting Member

37 Posts

Posted - 2006-02-28 : 15:24:24
Sorry. I mean if my query can get all record which between that rang. in the another word. if I use WHERE datatime BETWEEN DATEADD(dd, -60, @datetime) AND DATEADD(dd, 30, @datetime).
can I get all record during that rang? I am not sure. Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-28 : 15:26:57
Why don't you try running it first?

Tara Kizer
aka tduggan
Go to Top of Page

hong_ma
Starting Member

37 Posts

Posted - 2006-02-28 : 15:46:47
that's right. Thanks
Go to Top of Page
   

- Advertisement -