Connecting Tech Pros Worldwide Help | Site Map

Between Dates

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 29th, 2008, 03:32 AM
Newbie
 
Join Date: Aug 2008
Posts: 2
Default Between Dates

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,
Reply
  #2  
Old August 30th, 2008, 07:35 PM
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Age: 22
Posts: 3,542
Default

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

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 10:34 PM. Reason: Added [code] tags.
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.