hi ,
I've two tables holiday and schedule tables according to the branchId.With the help of two tables i need count of non working days.
##SLADCSchedule--This table has the date ranges i.e Effecctive from and effective to and discription of each day in that period.
##TestHoliday --Holiday table..
here 1- Working day
0-Holiday..
i have three parameters to pass
entrydate='=2014-01-19' shipdate = '2014 -01-21' branchId=1
since '2014-01-20' is holiday in holiday table and working day in ##SLADCSchedule- i need to get count as 1.
CREATE TABLE [dbo].##TestHoliday( [BranchId] [tinyint] NULL, [HolidayName] [varchar](50) NULL, [HolidayYear] [smallint] NULL, [HolidayDate] [date] NULL, [EffectiveFrom] [datetime] NULL, [EffectiveTo] [datetime] NULL ) INSERT INTO ##TestHoliday SELECT 1,'Christmas',2012,'2012-12-25','2012-01-01 00:00:00.000','2012-12-31 23:59:59.000' UNION ALL SELECT 1,'Martin Luther King Day',2014,'2014-01-20','2014-01-01 00:00:00.000','2014-12-31 23:59:59.000' UNION ALL SELECT 1,'Fourth of July',2014,'2014-07-04','2014-01-01 00:00:00.000','2014-12-31 23:59:59.000' UNION ALL SELECT 1,'New Year''s Day',2014,'2014-01-01','2014-01-01 00:00:00.000','2014-12-31 23:59:59.000' UNION ALL SELECT 1,'Christmas',2013,'2013-12-25','2013-01-01 00:00:00.000','2013-12-31 23:59:59.000' UNION ALL SELECT 1,'Christmas',2014,'2014-12-25','2014-01-01 00:00:00.000','2014-12-31 23:59:59.000' SELECT * FROM ##TestHoliday CREATE TABLE [dbo].##Schedule( [BranchId] [tinyint] NULL, [ScheduleYear] [smallint] NULL, [Sunday] [bit] NULL, [Monday] [bit] NULL, [Tuesday] [bit] NULL, [Wednesday] [bit] NULL, [Thursday] [bit] NULL, [Friday] [bit] NULL, [Saturday] [bit] NULL, [EffectiveFrom] [datetime] NULL, [EffectiveTo] [datetime] NULL) INSERT INTO dbo.##Schedule([BranchId],[ScheduleYear],[Sunday],[Monday],[Tuesday],[Wednesday],[Thursday],[Friday],[Saturday],[EffectiveFrom],[EffectiveTo]) SELECT 1,2014,1,1,1,1,1,1,1,'2014-01-21 00:00:00.000','2014-12-31 23:59:59.000' union ALL SELECT 1,2014,0,1,1,1,1,1,0,'2014-01-01 00:00:00.000','2014-01-20 23:59:59.000' UNION ALL SELECT 1,2013,0,1,1,1,1,1,0,'2013-01-01 00:00:00.000','2013-12-31 23:59:59.000' UNION ALL SELECT 1,2012,0,1,1,1,1,1,0,'2012-01-01 00:00:00.000','2012-12-31 23:59:59.000' SELECT * FROM dbo.##Schedule SELECT * FROM ##TestHoliday