SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

immad
Posting Yak Master

Pakistan
218 Posts

Posted - 08/15/2013 :  04:43:49  Show Profile  Reply with Quote
Hello

i have a query problem

this is my query

select
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.eid
where CONVERT (DATETIME,CONVERT (VARCHAR,CheckTIme,101))>'20130801' and CONVERT (DATETIME,CONVERT (VARCHAR,CheckTIme,101))<'20130815'
order by date


its gives me that result

eid--------name---------------date--------------attendance
1-----------A--------2013-08-02 00:00:00.000-------P
10----------B--------2013-08-02 00:00:00.000-------P
1015--------C--------2013-08-02 00:00:00.000-------P

but if some employee absent on that date its didnt show absent 'A'
becouse attendlog table didnt have absent employee data
please help me out





immad uddin ahmed

DonAtWork
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 08/15/2013 :  06:24:50  Show Profile  Reply with Quote
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

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30113 Posts

Posted - 08/15/2013 :  06:45:36  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 d
CROSS JOIN	dbo.Employee AS e
LEFT JOIN	dbo.AttendLog AS al ON al.eID = e.eID
			AND CAST(al.CheckTime AS DATE) = d.theDate;



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

immad
Posting Yak Master

Pakistan
218 Posts

Posted - 08/15/2013 :  08:47:34  Show Profile  Reply with Quote
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 data

for example this is a attend log data

eid-------checktime------------------status
25391----2013-01-01 06:51:00.000-------I
25391----2013-01-02 09:41:00.000-------I
25391----2013-01-03 08:20:00.000-------I
25391----2013-01-05 07:20:00.000-------I


this employee didnt come on 4 jan becouse he is absent so how its possible to retrive his absent data.

immad uddin ahmed
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000