I need to get the date from date table minus 3 days (business days to be specific). Below is the structure:
date business day
1/1/13 Y
1/2/13 N
1/3/13 Y
1/4/13 Y
1/5/13 Y
Suppose if todays date is 1/5/13 then I need to get current_date - 3(business)days which is 1/1/13 (since 1/2/13 is a non – business day)
This can be done with what is known as a ‘windowing’ function. The following should work on all (recent) versions of DB2 (untested, though, as I’m away from my instance):
Which should result in
2013-01-01.If you are doing a lot of similar math, I’d actually recommend creating stored procedures for this sort of thing, say something like
addBusinessDays(calendar_date, days_to_add). Although you have to access a table for it to work, you should be able to mark it asDETERMINISTIC(well, assuming the compiler lets you get away with that, and that days aren’t suddenly switched…)