Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Oracle SQL Decyphering

Author  Topic 

Xerxes
Aged Yak Warrior

666 Posts

Posted - 2012-05-14 : 15:19:59
Sorry, not sure where this topic goes, but I've come across some Oracle SQL code:

WHEN
to_number(to_char(CALENDAR_DT,'YYYY')) =
to_number(to_char(sysdate -1,'YYYY'))-1
THEN
next_day(CALENDAR_DATE + 363, to_char(CALENDAR_DT,"DAY'))

Could anyone tell me what this is doing or checking for?

Thanks...



Semper fi,
XERXES, USMC(Ret.)
------------------------------------------------------
The Marine Corps taught me everything but SQL & VB obviously!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-05-14 : 17:16:02
If GETDATE returns today (May 14, 2012), the right part is 2011.
If GETDATE returns January 1st 2012, the right part is 2010.

The return is the weekday that is 363 days or more after Calendar_Date that has the same weekday as Calendar_DT.
If the Calendar_Date + 363 is the same weekday as Calendar_DT, 7 more days is added to get the correct date.

So what is does, is to calculate the some weekday 1 year (and some days) later.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -