Connecting Tech Pros Worldwide Forums | Help | Site Map

Between Dates

Newbie
 
Join Date: Aug 2008
Posts: 2
#1: Aug 29 '08
Hi,

I'm new to SQL and I have the following quesiton.

I have table of data as follows:

Date
31-01-2007
12-31-2007
31-01-2008
31-12-2008

If a want to create an if statement that says if date falls between 31-01-2007 and 12-31-2007 put Year 1, if date falls between 31-01-2008 and 31-12-2008 put Year 2, etc.

Do I use the following formula:

CASE When Date >=31-01-2007 AND <=12-31-2007 THEN "Year 1,

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,748
#2: Aug 30 '08

re: Between Dates


Hi.

You could use the BETWEEN ... AND syntax. Like:
Expand|Select|Wrap|Line Numbers
  1. SELECT 2 BETWEEN 1 AND 3;
  2.  
Replacing the numbers with dates.
Newbie
 
Join Date: Aug 2008
Posts: 2
#3: Sep 4 '08

re: Between Dates


I figured it out the answer to my question
Expand|Select|Wrap|Line Numbers
  1. CASE WHEN Invoice Date BETWEEN '01-APR-2005' AND '31-MAR-2006' THEN '05-06' ELSE CASE WHEN Invoice Date BETWEEN '01-APR-2006' AND '31-MAR-2007' THEN '06-07' ELSE '0' END END
  2.  
Reply