0

I have a query and apple CASE funcation and getting error

(full) year must be between -4713 and +9999, and not be 0

This code is yielding the error:

NVL(     
CASE WHEN Ea.ASGACTSTART < add_months(SYSDATE,-12)  THEN 365
ELSE 
to_number( to_char(to_date('1','J') +
((SYSDATE -1) - Ea.ASGACTSTART), 'J') )
END , 0)  "Adujsted Days", 
Sebastian Lenartowicz
  • 4,695
  • 4
  • 28
  • 39
Assad Amjad
  • 29
  • 1
  • 9

2 Answers2

0

I think you can simply make

CASE WHEN Ea.ASGACTSTART < add_months(SYSDATE,-12)  THEN 365
ELSE NVL(SYSDATE - 1 - Ea.ASGACTSTART, 0)
END AS "Adujsted Days"
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • What is a "single value"? Surround it by `TRUNC()` or `ROUND()` if needed. – Wernfried Domscheit Jul 18 '17 at 14:32
  • Thanks i have formula in Excel but i dont need any formula in Excel is there anything that i convert excel formula to in Oracel Query here is the Excel formula =+IF(ISBLANK(@Enddate),IF($StartDate – Assad Amjad Jul 18 '17 at 14:43
0

Given:

create table tabby (ASGACTSTART date);
insert into tabby values (sysdate);

The problem is this part of your expression:

select 
   to_date('1','J') + ((SYSDATE -1) - Ea.ASGACTSTART)
from tabby ea;

If you change the + to , then you can see why it's a problem.

select 
   --to_date('1','J') + ((SYSDATE -1) - Ea.ASGACTSTART)
     to_date('1','J') , ((SYSDATE -1) - Ea.ASGACTSTART)
from tabby ea;

According to at least one other post, to_date('1','J') is intended to return the smallest possible date possible. However, the right-hand side of the + might be negative and therefore cause the RDBMS to complain.

The use case I created was intended to do just that.

Jeff Holt
  • 2,940
  • 3
  • 22
  • 29