Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 29th, 2008, 04: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, 08:35 PM
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Age: 22
Posts: 2,783
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, 04: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 11:34 PM. Reason: Added [code] tags.
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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 network members.
Post your question now . . .
It's fast and it's free

Popular Articles