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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to use EXISTS with conditions datetime
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mooppc
Starting Member

1 Posts

Posted - 11/28/2012 :  11:17:58  Show Profile  Reply with Quote
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. :)

Edited by - mooppc on 11/28/2012 11:31:57

webfred
Flowing Fount of Yak Knowledge

Germany
8781 Posts

Posted - 11/28/2012 :  11:34:55  Show Profile  Visit webfred's Homepage  Reply with Quote
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
  Previous Topic Topic Next 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