skj
skj

Reputation: 15

Increment the result by one in select statement

I want to increment the result by one when date in greater than 10 then. I want to increment by result by one in MONTHS_BETWEEN oracle function

select
dt1, dt2,
   CASE
   when 
    TRUNC( months_between(dt1,dt2) ) <= 0 then 0
   when
     TO_NUMBER(TO_CHAR( TO_DATE(dt2,'DD/MM/YYYY'),'DD')) > 10
     then
     TRUNC( months_between(dt1,dt2) )
   end as mths
from
(
    select date '2013-12-01' dt1, date '2013-12-25' dt2 from dual 
)

Upvotes: 0

Views: 82

Answers (1)

evenro
evenro

Reputation: 2646

your need is not clear...

The when.. then construct is a very basic one - from what I understood you need - I don't understand why you don't use:

CASE WHEN months_between(dt1,dt2) > 10 THEN add_months(dt2,1) ELSE dt2

or something like that...

If I did not give a broad enough answer for you to be able to solve the problem - please describe the problem with more details, and bring some examples of input and expected output...

Upvotes: 1

Related Questions