Solved

get previous Years data

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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
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.
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.

867 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

18 Experts available now in Live!

Get 1:1 Help Now