Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date Query - Last Full Year

Posted on 2007-03-19
1
Medium Priority
?
209 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month13 days, 1 hour left to enroll

971 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