Thank you very much Luis for looking into this.
This is very helpful. Sorry about 30 hours in a day.
I was just testing it and it looks very promising, but is failing for the below mentioned case.
In this case there are no rows where IsResSchedule = 1 but I am getting 2.
If I change the where IsResSchedule = 0 to AND IsResSchedule = 1 , the results for Resource 2 gets bad.
Again thank you very much for your help.
Insert into [W_O_Schedule]
Values
(3,4,'Available','Weekly','2000-01-04 09:00:00.000','2000-01-04 17:00:00.000',0),
(3,4,'Available','Weekly','2000-01-04 09:00:00.000','2000-01-04 17:00:00.000',1),
(3,4,'Unavailable','OneTime','2013-06-04 00:00:00.000','2013-06-05 00:00:00.000',0),
(3,4,'Unavailable','OneTime','2013-06-04 00:00:00.000','2013-06-05 00:00:00.000',1)