Solved

Retrieving last 14 months of data with SQL statement

Posted on 2006-06-29
3
363 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

776 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