Solved

Retrieving last 14 months of data with SQL statement

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 setup several different housekeeping processes for a SQL Server.

821 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