Need help with SQL

D

DevilDog1978

SELECT DISTINCTROW OUTLOOK_APPROVEt1.To, OUTLOOK_APPROVEt1.Subject,
OUTLOOK_APPROVEt1.Received, OUTLOOK_APPROVEt1.Contents,
OUTLOOK_APPROVEt1.CountOfImportance INTO OUTLOOK_APPROVEt2
FROM OUTLOOK_APPROVEt1
WHERE Received >= date_sub(curdate(), interval 1 month) and Received <=
date_sub(curdate(), interval 1 day)
WITH OWNERACCESS OPTION;

I am having trouble with the Where portion. I would like for this query to
reveal all the emails over the past physical month. Example February 1st I
would like to be able to collect the data for all of January. Any help would
be greatly appreciated.
 
J

John W. Vinson

SELECT DISTINCTROW OUTLOOK_APPROVEt1.To, OUTLOOK_APPROVEt1.Subject,
OUTLOOK_APPROVEt1.Received, OUTLOOK_APPROVEt1.Contents,
OUTLOOK_APPROVEt1.CountOfImportance INTO OUTLOOK_APPROVEt2
FROM OUTLOOK_APPROVEt1
WHERE Received >= date_sub(curdate(), interval 1 month) and Received <=
date_sub(curdate(), interval 1 day)
WITH OWNERACCESS OPTION;

I am having trouble with the Where portion. I would like for this query to
reveal all the emails over the past physical month. Example February 1st I
would like to be able to collect the data for all of January. Any help would
be greatly appreciated.

This looks like a mix of T-SQL and Access SQL...

If it's in Access, I'd use the DateSerial function (I'm not familiar with
date_sub if indeed that isn't just your placeholder).

WHERE Received >= DateSerial(Year(Date()), Month(Date()) - 1, 1) AND Received
< DateSerial(Year(Date()), Month(Date()), 1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top