I want to Calculate Number of Days that an Employee can work having Week Marked with Bit 1:CREATE TABLE #EMP( eid INT default 0, sun bit default 1, mon bit default 1, tue bit default 1, wed bit default 1, thu bit default 1, fri bit default 1, sat bit default 1)CREATE TABLE #EMPCHILD( eid INT default 0, [date] DATETIME)INSERT INTO #EMP VALUES(1,0,1,0,0,1,1,1)INSERT INTO #EMP VALUES(2,0,0,1,0,1,1,1)INSERT INTO #EMP VALUES(3,0,1,0,0,1,1,1)INSERT INTO #EMP VALUES(4,1,1,0,0,1,1,1)INSERT INTO #EMPCHILD VALUES(1,'2014-03-01')INSERT INTO #EMPCHILD VALUES(1,'2014-03-02')INSERT INTO #EMPCHILD VALUES(1,'2014-03-03')INSERT INTO #EMPCHILD VALUES(1,'2014-03-04')INSERT INTO #EMPCHILD VALUES(1,'2014-03-05')INSERT INTO #EMPCHILD VALUES(1,'2014-03-06')INSERT INTO #EMPCHILD VALUES(1,'2014-03-07')INSERT INTO #EMPCHILD VALUES(1,'2014-03-08')INSERT INTO #EMPCHILD VALUES(1,'2014-03-09')INSERT INTO #EMPCHILD VALUES(3,'2014-03-10')INSERT INTO #EMPCHILD VALUES(3,'2014-03-01')INSERT INTO #EMPCHILD VALUES(3,'2014-03-02')INSERT INTO #EMPCHILD VALUES(3,'2014-03-03')INSERT INTO #EMPCHILD VALUES(2,'2014-03-04')INSERT INTO #EMPCHILD VALUES(3,'2014-03-05')INSERT INTO #EMPCHILD VALUES(4,'2014-03-06')INSERT INTO #EMPCHILD VALUES(2,'2014-03-07')INSERT INTO #EMPCHILD VALUES(4,'2014-03-08')INSERT INTO #EMPCHILD VALUES(3,'2014-03-09')INSERT INTO #EMPCHILD VALUES(3,'2014-03-10')INSERT INTO #EMPCHILD VALUES(2,'2014-03-01')INSERT INTO #EMPCHILD VALUES(3,'2014-03-01')INSERT INTO #EMPCHILD VALUES(4,'2014-03-01')INSERT INTO #EMPCHILD VALUES(2,'2014-03-02')INSERT INTO #EMPCHILD VALUES(3,'2014-03-01')INSERT INTO #EMPCHILD VALUES(1,'2014-03-01')INSERT INTO #EMPCHILD VALUES(2,'2014-03-03')INSERT INTO #EMPCHILD VALUES(4,'2014-03-04')INSERT INTO #EMPCHILD VALUES(3,'2014-03-01')SELECT * from #EMPSELECT * from #EMPCHILDDROP TABLE #EMPDROP TABLE #EMPCHILD
I have applied this query and got the result:SELECT #EMP.eid,COUNT(*) FROM #EMPLEFT JOIN #EMPCHILD ON #EMPCHILD.eid = #EMP.eidWHERE #EMPCHILD.[Date] between '2014-03-01' AND '2014-03-08'GROUP BY #EMP.eid
Now I want result set as following Image:[url]https://drive.google.com/file/d/0ByQA_cbUshlua0FNRDBrc1k2ZjQ/edit?usp=sharing[/url]Kindly anybody help