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.
Author |
Topic |
immad
Posting Yak Master
230 Posts |
Posted - 2013-08-15 : 04:43:49
|
Helloi have a query problemthis is my queryselect distinct a.eid,e.ename,CONVERT (DATETIME,CONVERT (VARCHAR,CheckTIme,101)) Date,case when a.status='I' and a.status= 'O' then '' else 'P' end Attendance,from attendlog a left outer join employee e on a.eid = e.eidwhere CONVERT (DATETIME,CONVERT (VARCHAR,CheckTIme,101))>'20130801' and CONVERT (DATETIME,CONVERT (VARCHAR,CheckTIme,101))<'20130815'order by dateits gives me that resulteid--------name---------------date--------------attendance1-----------A--------2013-08-02 00:00:00.000-------P10----------B--------2013-08-02 00:00:00.000-------P1015--------C--------2013-08-02 00:00:00.000-------Pbut if some employee absent on that date its didnt show absent 'A'becouse attendlog table didnt have absent employee dataplease help me outimmad uddin ahmed |
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2013-08-15 : 06:24:50
|
case when a.status='I' and a.status= 'O' then '' else 'P' end Attendance This line will always return 'P'.How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-08-15 : 06:45:36
|
[code]SELECT e.eID, e.eName, d.theDate AS [Date], CASE WHEN al.[Status] IS NULL THEN 'A' WHEN al.[Status] IN ('I', 'O') THEN '' ELSE 'P' END Attendance,FROM ( SELECT CAST(CheckTime AS DATE) AS theDate FROM dbo.AttendLog WHERE CheckTime >= '20130801' AND CheckTime < '20130815' GROUP BY CAST(CheckTime AS DATE) ) AS dCROSS JOIN dbo.Employee AS eLEFT JOIN dbo.AttendLog AS al ON al.eID = e.eID AND CAST(al.CheckTime AS DATE) = d.theDate;[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
immad
Posting Yak Master
230 Posts |
Posted - 2013-08-15 : 08:47:34
|
actually there is no absent data in attend log i mean only that employee attendance data insert whose present in factory if a employee is absent then there is no data in attendlog so how i can retrive that datafor example this is a attend log data eid-------checktime------------------status25391----2013-01-01 06:51:00.000-------I25391----2013-01-02 09:41:00.000-------I25391----2013-01-03 08:20:00.000-------I25391----2013-01-05 07:20:00.000-------Ithis employee didnt come on 4 jan becouse he is absent so how its possible to retrive his absent data. immad uddin ahmed |
|
|
|
|
|
|
|