Solved

get previous Years data

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

746 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

8 Experts available now in Live!

Get 1:1 Help Now