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)
 Yesterday's Date

Author  Topic 

adlo
Posting Yak Master

108 Posts

Posted - 2004-09-16 : 08:06:35
What is the most efficient sql statement to do the following:

I need to get a list of users (e-mail addresses) who were created yesterday.
The UserTable :User_ID,EMail,DateCreated(DateTime)

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-16 : 08:12:15
IMHO:

select * from UserTable where day(DateCreated) = day(dateadd(d, -1, getdate()))

Go with the flow & have fun! Else fight the flow
Go to Top of Page

adlo
Posting Yak Master

108 Posts

Posted - 2004-09-16 : 08:36:49
I need a query that gives back only yesterday's entries and should not include yesterday a month/year ago.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-09-16 : 08:38:35
A little tweak:

SELECT * FROM userTable WHERE DateDiff(day, DateCreated, getdate())=-1
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-16 : 08:41:23
hey that is kool!!

Go with the flow & have fun! Else fight the flow
Go to Top of Page

adlo
Posting Yak Master

108 Posts

Posted - 2004-09-16 : 08:45:06
Thanks robvolk

The query I had previously
select Email from UserTable where CONVERT(CHAR(10),DateCreated,111) = CONVERT(CHAR(10),dateadd(d, -1, getdate()),111)

New query
SELECT * FROM Accountuser WHERE DateDiff(day, DateCreated, getdate())=1
Go to Top of Page
   

- Advertisement -