Question : Calculating the date.

Hi,
I am using the Oracle database. There are three columns start date, end month and end day. The combination of endmonth,end day and year must become the end date.for eg
                                    startdate             endday         end month           enddate
   case1:                        05/21/2010          21                  11                      11/21/2010
   case2:                        05/21/2010          15                    1                      1/15/2011
In my database we have  the first three column but the end date should be calculated.usually to calculate the end date we have to keep the difference between start date and end date is more then 6 months. I am able to consider the year six months from the start date but that fails for the "case 2".
is there any work around this?

Answer : Calculating the date.


SELECT start_date, endday, endmonth,
CASE
WHEN start_date < 
ADD_MONTHS (TRUNC (start_date, 'YYYY'),
endmonth - 1
)
+ endday
- 1
THEN ADD_MONTHS (TRUNC (start_date, 'YYYY'), endmonth - 1)
+ endday
- 1
ELSE ADD_MONTHS (TRUNC (start_date, 'YYYY'), endmonth + 11)
+ endday
- 1
END end_date
FROM ............

Random Solutions  
 
programming4us programming4us