﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / How to use NOT IN or Not Exist custom in Datetime? / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 18 May 2013 23:13:45 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: How to use NOT IN or Not Exist custom in Datetime?</title><link>http://www.sqlservercentral.com/Forums/Topic1394711-392-1.aspx</link><description>[quote][b]Eugene Elutin (12/10/2012)[/b][hr]Hope that following should help you:[code="sql"]SELECT tf.EmpNo, tf.ChkDateFROM filesTA tf WHERE tf.ChkDate BETWEEN '20121001' AND '20121005'  AND NOT EXISTS (SELECT 1 FROM SalaryDay2 sd2                 WHERE   sd2.sEmpNo = tf.EmpNo                    AND sd2.sDate = tf.ChkDate)                                        [/code]Please note: 1. Never convert datetime to anything else (varchar or int) for datetime comparison. If your SalaryDay2.sDate is varchar, convert it to datetime instead (or it will be properly implicitly converted if it's in ISO)2. Note the format I've used - it's one of possible ISO variations: Year then Month then Day. You can use '1 Oct 2012', it will also work perfectly as month is explicitly known.3. Used BETWEEN will only work properly if your datetime values do not contain time part. Otherwise, you should use greater-than-or-equal-to and less-than in WHERE clause for datetime filtering: WHERE tf.ChkDate &amp;gt;= '20121001' AND tf.ChkDate &amp;lt; '20121006'  --note the "to" boundary...[/quote]Oh, thanks so much! i'm learnings this news. :-P</description><pubDate>Mon, 10 Dec 2012 12:26:33 GMT</pubDate><dc:creator>ppc493</dc:creator></item><item><title>RE: How to use NOT IN or Not Exist custom in Datetime?</title><link>http://www.sqlservercentral.com/Forums/Topic1394711-392-1.aspx</link><description>Hope that following should help you:[code="sql"]SELECT tf.EmpNo, tf.ChkDateFROM filesTA tf WHERE tf.ChkDate BETWEEN '20121001' AND '20121005'  AND NOT EXISTS (SELECT 1 FROM SalaryDay2 sd2                 WHERE   sd2.sEmpNo = tf.EmpNo                    AND sd2.sDate = tf.ChkDate)                                        [/code]Please note: 1. Never convert datetime to anything else (varchar or int) for datetime comparison. If your SalaryDay2.sDate is varchar, convert it to datetime instead (or it will be properly implicitly converted if it's in ISO)2. Note the format I've used - it's one of possible ISO variations: Year then Month then Day. You can use '1 Oct 2012', it will also work perfectly as month is explicitly known.3. Used BETWEEN will only work properly if your datetime values do not contain time part. Otherwise, you should use greater-than-or-equal-to and less-than in WHERE clause for datetime filtering: WHERE tf.ChkDate &amp;gt;= '20121001' AND tf.ChkDate &amp;lt; '20121006'  --note the "to" boundary...</description><pubDate>Mon, 10 Dec 2012 11:16:01 GMT</pubDate><dc:creator>Eugene Elutin</dc:creator></item><item><title>How to use NOT IN or Not Exist custom in Datetime?</title><link>http://www.sqlservercentral.com/Forums/Topic1394711-392-1.aspx</link><description>i use 2 table, i want first table not data in table two of show on to database.[b]Ex. "filesTA"[/b][quote]EmpNo | ChkDate00001 | 2012-10-01 00:00:00.00000001 | 2012-10-02 00:00:00.00000001 | 2012-10-03 00:00:00.00000001 | 2012-10-04 00:00:00.00000001 | 2012-10-05 00:00:00.000[/quote][b]"SalaryDay2"[/b][quote]sEmpNo | sDate00001 | 2012-10-01 00:00:00.00000001 | 2012-10-02 00:00:00.000[/quote][b]When i select datetime between 2012-10-01 and 2012-10-05i need output:[/b][quote]sEmpNo | sDate00001 | 2012-10-03 00:00:00.00000001 | 2012-10-04 00:00:00.00000001 | 2012-10-05 00:00:00.000[/quote][b]this code:[/b][quote]SELECT tf.EmpNo,tf.ChkDateFROM filesTA tf WHERE tf.ChkDate NOT IN(SELECT sd2.sDateFROM SalaryDay2 sd2WHERE Convert(nvarchar(10),sd2.sDate,126) Between '2012-10-01' and '2012-10-05')[/quote][b]please help me. thanks you for you time. :)[/b]</description><pubDate>Mon, 10 Dec 2012 10:53:38 GMT</pubDate><dc:creator>ppc493</dc:creator></item></channel></rss>