Solved

Need SQL code to query month to date last year

Posted on 2014-10-29
4
710 Views
Last Modified: 2014-10-30
I am trying to build a query in Access 2010 to pull data from month to date last year.

Example. today being 10/29/14, I am using Between DateAdd("d",-DatePart("d",Date())+1,Date()) And Date()-1 which pulls my data for 10/1/2014 to 10/28/2014

I am trying to look a comparable sales data so I need a piece of code that pulls 10/1/2013 to 10/28/2013
0
Comment
Question by:Cole100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40411906
Did you try this:

dateadd("y",-1,DateAdd("d",-DatePart("d",Date())+1,Date()) ) and dateadd("y",-1,Date()-1)
0
 
LVL 19

Accepted Solution

by:
Eric Sherman earned 250 total points
ID: 40412006
Also try this for month to date last year ...

Between DateSerial(Year(Date())-1, Month(Date()), 1) AND DateSerial(Year(Date())-1, Month(Date()), Day(Date())-1)

ET
0
 
LVL 50

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 total points
ID: 40412634
You could use for the current year:

    Between DateSerial(Year(Date()), Month(Date()), 1) And DateAdd("d", -1,Date())

and for last year:

     Between DateSerial(Year(Date()) - 1, Month(Date()), 1) And DateAdd("yyyy", -1, DateAdd("d", -1,Date()))

etsherman's expression for the last year is valid too. A matter of taste.

/gustav
0
 

Author Closing Comment

by:Cole100
ID: 40413926
Both etsherman and gustav solution did exactly as i  needed. thank you
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question