Connecting Tech Pros Worldwide Help | Site Map

Between Dates

  #1  
Old August 29th, 2008, 04:32 AM
Newbie
 
Join Date: Aug 2008
Posts: 2
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,
  #2  
Old August 30th, 2008, 08:35 PM
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,702
Provided Answers: 4

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.
  #3  
Old September 4th, 2008, 04:25 AM
Newbie
 
Join Date: Aug 2008
Posts: 2

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.  

Last edited by Atli; September 4th, 2008 at 11:34 PM. Reason: Added [code] tags.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Between Dates @sh answers 15 September 13th, 2006 11:05 PM
List dates between dates pitfour.ferguson@mac.com answers 1 August 1st, 2006 12:05 PM
Calculating between dates on separate records Carl answers 2 June 23rd, 2006 10:15 PM
VB6 - hours between dates/times Don G answers 1 June 16th, 2006 04:55 PM
Number of months between dates MMFBprez answers 3 November 13th, 2005 04:42 AM