Solved

Date Query - Last Full Year

Posted on 2007-03-19
1
199 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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.…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

22 Experts available now in Live!

Get 1:1 Help Now