How about this one which will not read any rows..jus a calculation and i suppose will be fastest !!
PS : I have tested for few cases, not thoroughly tested...but seems ok to me.Code:Select Dayz - Nvl(Floor(Round((Dayz+Add_To_Dayz)/7,2)) * 2, 0) Week_Days From ( Select Trunc(End_Date) - Trunc(Start_Date) - Decode(Substr(To_Char(Start_Date, 'DAY'), 1, 3), 'SUN', 1, 'SAT', 2, 0 ) - Decode(Substr(To_Char(End_Date, 'DAY'), 1, 3), 'SUN', 2, 'SAT', 1, 0 ) + 1 Dayz, Decode(Substr(To_Char(Start_Date, 'DAY'), 1, 3), 'MON', 1, 'TUE', 2, 'WED', 3, 'THU', 4, 'FRI', 5, 0 ) Add_To_Dayz From Dual ) ;
Abhay.




Reply With Quote