Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 SQL Server Administration (2012)
 Store Procedure For Attendance

Author  Topic 

kallsy45
Starting Member

1 Post

Posted - 2013-12-13 : 09:51:50

Hi Frnds,

Can you please help me regarding a stored procedure which calculates monthly attendance for all employees.I am having a attendance table which has following fields:
The start date & end date for a month will be user input.It will check day by day.If any date is absent then it status will be 'A', otherwise status will be 'P'.

Please help me.









———————————————————————————————————
http://www.airmax1shop.nl

[url=http://airmax1shop.nl]<b>Air max 90</b>[/url]
[url=http://www.airmax1shop.nl]<b>Air Max 90 sneaker</b>[/url]
[url=http://airmax1shop.nl]<b>Airmax1shop.nl</b>[/url]

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-12-13 : 11:00:55
Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-14 : 07:38:24
you need to use a calendar table for that.
logic will be like below

SELECT c.CalendarDate,
CASE WHEN t.DateColumn IS NULL THEN 'A' ELSE 'P' END
FROM CalendarTable c
LEFT JOIN YourTable t
ON t.DateColumn = c.CalendarDate
WHERE c.CalendarDate > = @StartDate
AND c.CalendarDate < @EndDate + 1
AND DATEDIFF(dd,0,c.CalendarDate)%7 <=4

you need to declare @StartDate and @EndDate as parameters
if you dont already have a calendartable use this instead


SELECT c.CalendarDate,
CASE WHEN t.DateColumn IS NULL THEN 'A' ELSE 'P' END
FROM dbo.CalendarTable(@StartDate,@EndDate,1,0) c
LEFT JOIN YourTable t
ON t.DateColumn = c.[Date]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -