select w.calendar_code,
w.sr_instance_id,
w.exception_set_id,
w.week_start_date week_start_date,
w.next_date-1/86400 week_end_date,
w.next_date - w.week_start_date day_count,
to_char(w.week_start_date,'YYYY/MM/DD') week_name ,
p.period_start_date
from MSC_CAL_WEEK_START_DATES w,msc_calendars m,MSC_PERIOD_START_DATES p
where m.calendar_code =fnd_profile.value('MSC_HUB_CAL_CODE')
and m.calendar_code = w.calendar_code
and m.sr_instance_id = w.sr_instance_id
and p.calendar_code = m.calendar_code
and p.sr_instance_id = w.sr_instance_id
and p.exception_set_id = w.exception_set_id
and p.period_start_date <=w.week_start_date
and p.next_date>w.week_start_date