Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

get previous Years data

Posted on 2013-01-03
2
Medium Priority
?
421 Views
Last Modified: 2013-01-03
I have the following code that gets all request where the Start Date and End Date fall in the current year. What I now need it to do is get all the request from 2012 or last years data.

( YEAR(StartDateAndTime) = YEAR(GETDATE())
                                  OR YEAR(EndDateAndTime) = YEAR(GETDATE())
                                )
0
Comment
Question by:mburk1968
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
djoray earned 2000 total points
ID: 38741367
To get last year's data, you can subtract 1 from the YEAR(GETDATE()) result

( YEAR(StartDateAndTime) = YEAR(GETDATE())-1
                                  OR YEAR(EndDateAndTime) = YEAR(GETDATE())-1
                                )
0
 
LVL 8

Expert Comment

by:jpgobert
ID: 38741376
If you're looking for the code you need for the date ranges where StartDateAndTime & EndDateAndTime are the variables then try the following:

Select * from TABLE where StartDateAndTime > '2011-12-31 23:59:59' and EndDateAndTime < '2013-01-01 00:00:00'

Is this what you're talking about or are you looking for something dynamic?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

609 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