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
 Leaves
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

immad
Posting Yak Master

Pakistan
222 Posts

Posted - 08/17/2013 :  01:17:55  Show Profile  Reply with Quote
Hi.

i am using this query.


SELECT
w.eID, w.ename,
COALESCE(al.CheckTime, c.[Date]) AS [Date]
,CASE WHEN al.CheckTime IS NULL THEN ld.Description ELSE 'P' END AS Attendance
FROM dbo.employee AS w
CROSS JOIN dbo.Calendar AS c
LEFT JOIN dbo.AttendLog AS al
ON al.eID = w.eID
AND DATEDIFF(DAY, al.CheckTime, c.[Date]) = 0
left join LeaveInformation l on COALESCE(al.CheckTime, c.[Date]) =l.date
left join LeaveDescription ld on l.lid =ld.lid

WHERE c.[Date] = '20130815'


when i write ld.Description its gives me null data like this

eid----------name--------------date----------------attendance
101881--------A----2013-08-15 00:00:00.000-----------NULL
101798--------B----2013-08-15 00:00:00.000-----------NULL
101775--------C----2013-08-15 00:00:00.000-----------NULL

but when i use 'A' instead of ld.Description its gives me that result

eid----------name--------------date----------------attendance
101881--------A----2013-08-15 00:00:00.000-----------A
101798--------B----2013-08-15 00:00:00.000-----------A
101775--------C----2013-08-15 00:00:00.000-----------A

Please help me out

i want to write ld.descriprtion instead of A





immad uddin ahmed

Edited by - immad on 08/17/2013 02:26:06

SwePeso
Patron Saint of Lost Yaks

Sweden
30282 Posts

Posted - 08/17/2013 :  04:56:51  Show Profile  Visit SwePeso's Homepage  Reply with Quote
How about you are going to post ALL relevant information at once, so that we don't have to guessplay over and over again for ecvery new requirement you can come up with?
This is at least the third post with new information you provide.



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

immad
Posting Yak Master

Pakistan
222 Posts

Posted - 08/17/2013 :  06:17:54  Show Profile  Reply with Quote
well my all work complete just one thing is remaining if a person is absent then its leave come like this
eid-------name---------------date---------------attendance
146---------A----------2013-07-01 00:00:00.000-------Absent
26538-------B----------2013-07-01 00:00:00.000-----2
102287------C----------2013-07-01 00:00:00.000-----1

if its leave are in leave table then show leave if it not then show absent

this is a leave table

eid---------date-------------------lid
26538----2012-07-01 00:00:00.000----2
102287----2012-07-01 00:00:00.000----1

this is my query




SELECT
case when w.leavingdate is null then w.eID else null end eid
,case when w.leavingdate is null then w.ename else '' end name
,case when w.leavingdate is null then COALESCE(al.CheckTime, c.[Date]) else null end Date
,CASE WHEN NULLIF (CONVERT(VARCHAR(16), COALESCE(al.CheckTime, c.[Date]), 14), '00:00:00:000') IS NULL THEN 'A' ELSE 'P' END AS Absent
FROM dbo.employee AS w
CROSS JOIN dbo.Calendar AS c
LEFT JOIN dbo.AttendLog AS al
ON al.eID = w.eID
AND DATEDIFF(DAY, al.CheckTime, c.[Date]) = 0
left join LeaveInformation l on COALESCE(al.CheckTime, c.[Date]) =l.date
left join LeaveDescription ld on ld.lid =l.lid
WHERE c.[Date] = '20130701'

please help me out
thanks



immad uddin ahmed

Edited by - immad on 08/17/2013 06:18:52
Go to Top of Page

namman
Constraint Violating Yak Guru

USA
272 Posts

Posted - 08/17/2013 :  12:29:15  Show Profile  Reply with Quote
Not sure what you want, but if I understand correctly, you should move the where clause to the right place, like this:

SELECT
case when w.leavingdate is null then w.eID else null end eid
,case when w.leavingdate is null then w.ename else '' end name
,case when w.leavingdate is null then COALESCE(al.CheckTime, c.[Date]) else null end Date
,CASE WHEN NULLIF (CONVERT(VARCHAR(16), COALESCE(al.CheckTime, c.[Date]), 14), '00:00:00:000') IS NULL THEN 'A' ELSE 'P' END AS Absent
FROM dbo.employee AS w
CROSS JOIN dbo.Calendar AS c
LEFT JOIN dbo.AttendLog AS al
ON al.eID = w.eID and c.[Date] = '20130701'
AND DATEDIFF(DAY, al.CheckTime, c.[Date]) = 0
left join LeaveInformation l on COALESCE(al.CheckTime, c.[Date]) =l.date
left join LeaveDescription ld on ld.lid =l.lid
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 08/18/2013 :  04:37:55  Show Profile  Reply with Quote
Sorry will it matter here as its a CROSS JOIN that OP is taking with Calendar table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.16 seconds. Powered By: Snitz Forums 2000