Solved

get previous Years data

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

773 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