Solved

Retrieving last 14 months of data with SQL statement

Posted on 2006-06-29
3
361 Views
Last Modified: 2011-09-20
I have a query that currently pulls all data since May of 2005.  The report that utilizes this data only needs 14 months of data to run.  How can I set up the query below to pull only the last 14 months of data going back from the current date?  Preferably the solution will be placed within the where statement.  All queries are run from MS Query within Excel XP.  Thanks in advance.


Select *
From Table A
Where fundeddate>'20050430'
0
Comment
Question by:srejja
  • 2
3 Comments
 
LVL 18

Expert Comment

by:ShogunWade
ID: 17013924
Select *
From Table A
Where fundeddate<DATEADD(month,-14,getdate())
0
 
LVL 18

Accepted Solution

by:
ShogunWade earned 350 total points
ID: 17013927
correction:

Select *
From Table A
Where fundeddate>=DATEADD(month,-14,getdate())
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 150 total points
ID: 17015985
if you want the full month (starting from day 1 of that month:

declare @startdate datetime
set @startdate = DATEADD(month,-14,getdate())
set @startdate = DATEADD(day,1-datepart(day,@startdate),@startdate)
set @startdate = convert(datetime, convert(varchar(10), @startdate,120), 120)

Select *
From Table A
Where fundeddate>@startdate
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now