JeffreyLazo
JeffreyLazo

Reputation: 853

SQL - Get data for yesterday and day before

I am running this query:

select member, customerinfo.customerid -- ...other irrelevant columns...
from customerinfo, addressinfo
    where customerinfo.customerid = addressinfo.customerid
    and MEMBER = (Date(GetDate()-1))
    and addressinfo.addresstype = 's'

I it is obviously giving me data if Member = yesterday.

My question is, how do I structure the query to give me data if Member = the last 2 days (yesterday and the day before)?

Upvotes: 5

Views: 46945

Answers (2)

Habib
Habib

Reputation: 223257

MEMBER BETWEEN (GETDATE() -2) AND (GETDATE() -1)

In SQL Server you can also try:

MEMBER BETWEEN DATEADD(day, -2, GETDATE()) AND DATEADD(day, -1, GETDATE())

Upvotes: 15

Joe Taras
Joe Taras

Reputation: 15379

Change your query in:

SELECT member, customerinfo.customerid, ContactName, Address1,
Address2, City, State, ZIP, Country from customerinfo, addressinfo
WHERE customerinfo.customerid = addressinfo.customerid
and MEMBER >= (Date(GetDate()-2)) AND MEMBER <= (Date(GetDate()-1))
and addressinfo.addresstype = 's'

Upvotes: 1

Related Questions