简体   繁体   中英

Query working days from calendar in CRM 2015

I have created a calendar (working days) for a resource (eg facility). How can I get a list or at least ranges of working days directly from the database?

All I have found so far are Calendar and CalendarRule views. The problem with the CalendarRule is that the rule is written with a pattern like

"FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR"

I can not find a way to use this in SQL query.

Assuming working days are mon to fri and your calendar table is linked to the resources table by calendar.workingdays = resources.daysworked , if not obviously adjust them to suit.

SELECT EXTRACT(dow FROM timestamp (to_timestamp(c.workingdays), "YYYY-MM-DD")), r.facility
FROM Calendar c
LEFT JOIN Resources r ON c.workingdays = r.daysworked
WHERE EXTRACT(dow FROM timestamp (to_timestamp(c.workingdays, "YYYY-MM-DD"))
NOT IN (0,6)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM