Solved

get previous Years data

Posted on 2013-01-03
2
418 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 500 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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

726 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