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)
 get the last 14 days

Author  Topic 

monfu
Yak Posting Veteran

81 Posts

Posted - 2005-11-24 : 18:34:06
Dear All,

I am creating a report to get the last transaction done between today and the last 14 days

My where clause is like this:-

WHERE (date_posted >= GETDATE()) AND (date_posted <= GETDATE() - 14)

for some reason its not working fine

Is the syntax correct?

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-24 : 19:21:38
WHERE (date_posted <= GETDATE()) AND (date_posted >= GETDATE() - 14)
same as
WHERE date_posted between GETDATE() - 14 and GETDATE()

or you might want
WHERE date_posted between convert(varchar(8),GETDATE() - 14,112) AND convert(varchar(8),GETDATE(),112)
if you are dealing with dates rather than datetimes


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

monfu
Yak Posting Veteran

81 Posts

Posted - 2005-11-24 : 19:47:17
oh thanks mate!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-25 : 00:18:42
or

WHERE date_posted between DateAdd(day,DateDiff(day,0,GETDATE() - 14),0) AND DateAdd(day,DateDiff(day,0,GETDATE()),0)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -