Solved

Date Query - Last Full Year

Posted on 2007-03-19
1
197 Views
Last Modified: 2010-03-20
I am using the following query to bring back data from the start of the year to the end of the last month.

The date is datetime field

where  year(acd.startdatetime) = year(getdate()) and  month(acd.startdatetime) <= Month(getdate()) - 1

I now need to a query to bring back the last full years data i.e. 2006 Jan 1st - Dec 31. This will then be run on the 1st of January every year to bring back the previous years data.

Can anybody help?
0
Comment
Question by:halifaxman
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 18748045
declare @startdate datetime
set @startdate = convert(datetime, cast (year(getdate())-1 as varchar(4)) + '-01-01', 120)
select ...
where  acd.startdatetime>= @startdate
and acd.startdatetime< dateadd(year, 1, @startdate)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

21 Experts available now in Live!

Get 1:1 Help Now