I have a problem to solve. Here how it goes…
An employee goes on a leave or vacation and this entry is logged in a table with LEAVE_START_DATE and NO_OF_DAYS (which is number of business days).
A master table contains DATE, IS_WEEK_DAY (Y/N), IS_HOLIDAY (Y/N), and DAY_OF_WEEK.
It is required to generate a list of business dates on which the employee was on holiday.
Table leaves
LEAVE_START_DATE, NO_OF_DAYS
2012-05-17, 3
Table days
DATE, IS_WEEK_DAY, IS_HOLIDAY, DAY_OF_WEEK
2012-05-17, Y, N, 5
2012-05-18, Y, N, 6
2012-05-19, N, N, 7
2012-05-20, N, N, 1
2012-05-21, Y, Y, 2
2012-05-22, Y, N, 3
Expected results
DATE
2012-05-17
2012-05-18
2012-05-22
I must be oversimplifying – Are you asking to select the 3 days from
table days(which is already populated) that matches the parameters of start date and business days? If so, the below will work. Also, you aren’t showing what version ofSQL SERVER, so if it is before 2005 you will have to work around theparameterized TOPwithROWCOUNTor whatever you prefer.