Hi All,
Can this query be further shrinked/optimized?
I am getting here the first working day of the month.
xxwfs_get_work_day is a function based on a holiday table which returns "1" for a federal holiday, "2" for saturday and sunday and "0" for a working day.
Thanks in advance!
Can this query be further shrinked/optimized?
I am getting here the first working day of the month.
xxwfs_get_work_day is a function based on a holiday table which returns "1" for a federal holiday, "2" for saturday and sunday and "0" for a working day.
SQL:
SELECT (CASE
WHEN xxwfs_get_work_day
(CASE
WHEN (TO_CHAR (TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON''), ''DY'')) = ''SUN''
THEN TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''),''MON'')+1
WHEN (TO_CHAR (TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON''), ''DY'')) = ''SAT''
THEN TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON'')+2
ELSE TRUNC (TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON'')
END, ''USA'') = 1
THEN
CASE
WHEN (TO_CHAR (TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON''), ''DY'')) = ''SUN''
THEN TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON'')+1
WHEN (TO_CHAR (TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON''), ''DY'')) = ''SAT''
THEN TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON'')+2
ELSE TRUNC (TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON'')
END+1
ELSE CASE
WHEN (TO_CHAR (TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON''), ''DY'')) = ''SUN''
THEN TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON'')+1
WHEN (TO_CHAR (TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON''), ''DY'')) = ''SAT''
THEN TRUNC(TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON'')+2
ELSE TRUNC (TO_DATE ('''||as_of_dt||''', ''DD-MM-YY HH24:MI:SS''), ''MON'')
END
END) T
FROM DUAL
Thanks in advance!