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 2008 Forums
 Transact-SQL (2008)
 How to use EXISTS with conditions datetime

Author  Topic 

mooppc
Starting Member

1 Post

Posted - 2012-11-28 : 11:17:58
i need show datetime select only. But show all datetime in table filesTA.

this code:
SELECT *
FROM filesTA tf
WHERE EXISTS
(
SELECT *
FROM filesTA tf left join LeaveRecord lr ON tf.ChkDate = lr.StartDate and tf.ChkDate = '2012-10-01'
WHERE lr.StartDate = '2012-10-01'
)


OR Code:
SELECT *
FROM filesTA tf
WHERE NOT tf.EmpNo
IN (
SELECT lr.EmployeeRun
FROM LeaveRecord lr
WHERE lr.StartDate = '2012-10-01'
)


Output:
EmpNo | ChkDate | ChkIn | ChkOut
00001 | 2012-10-01 00:00:00.000 | 2012-10-01 07:21:00.000 | 2012-10-01 12:21:00.000
00002 | 2012-10-01 00:00:00.000 | 2012-10-01 08:13:00.000 | 2012-10-01 19:55:00.000
00003 | 2012-10-15 00:00:00.000 | 2012-10-15 07:06:00.000 | 2012-10-15 20:12:00.000
00004 | 2012-10-22 00:00:00.000 | 2012-10-22 07:12:00.000 | 2012-10-22 19:15:00.000

I need Output:
EmpNo | ChkDate | ChkIn | ChkOut
00001 | 2012-10-01 00:00:00.000 | 2012-10-01 07:21:00.000 | 2012-10-01 12:21:00.000
00002 | 2012-10-01 00:00:00.000 | 2012-10-01 08:13:00.000 | 2012-10-01 19:55:00.000

THANKS FOR YOUR TIME.

I'm beginnig ASP.NET. Nice to meet you. :)

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-11-28 : 11:34:55
SELECT tf.*
FROM filesTA tf
inner join LeaveRecord lr ON tf.ChkDate = lr.StartDate and tf.ChkDate = '20121001'



Too old to Rock'n'Roll too young to die.
Go to Top of Page
   

- Advertisement -