<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; 2005 Comparison EXCEPT operator vs. NOT IN</title>
	<atom:link href="http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57124</link>
		<dc:creator>pinaldave</dc:creator>
		<pubDate>Wed, 28 Oct 2009 23:05:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57124</guid>
		<description>Thanks Brian,

Very good point!</description>
		<content:encoded><![CDATA[<p>Thanks Brian,</p>
<p>Very good point!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Waseem</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57093</link>
		<dc:creator>Waseem</dc:creator>
		<pubDate>Wed, 28 Oct 2009 05:50:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57093</guid>
		<description>Thanks for sharing the needed information!</description>
		<content:encoded><![CDATA[<p>Thanks for sharing the needed information!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57084</link>
		<dc:creator>Brian Tkatch</dc:creator>
		<pubDate>Tue, 27 Oct 2009 17:58:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57084</guid>
		<description>@Sucharitha

I don&#039;t know of any. (Though i am not an expert.)

It seems that every field would need to be scanned, resulting in a full table scan. Indexing won&#039;t even help because it would be indexing off the description and not the part that you want.</description>
		<content:encoded><![CDATA[<p>@Sucharitha</p>
<p>I don&#8217;t know of any. (Though i am not an expert.)</p>
<p>It seems that every field would need to be scanned, resulting in a full table scan. Indexing won&#8217;t even help because it would be indexing off the description and not the part that you want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sucharitha</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57081</link>
		<dc:creator>Sucharitha</dc:creator>
		<pubDate>Tue, 27 Oct 2009 16:27:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57081</guid>
		<description>Hello Brian,

Thank you for the suggestion which was obviously in my mind. I am new into the team and company, and the application has been built and stabilised. I need to study it better before i make any changes to the DB.
But at this time,  I have been asked to get a quick report where I need to filter on something like this. Is there any other quick solution running in your mind?</description>
		<content:encoded><![CDATA[<p>Hello Brian,</p>
<p>Thank you for the suggestion which was obviously in my mind. I am new into the team and company, and the application has been built and stabilised. I need to study it better before i make any changes to the DB.<br />
But at this time,  I have been asked to get a quick report where I need to filter on something like this. Is there any other quick solution running in your mind?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57077</link>
		<dc:creator>Brian Tkatch</dc:creator>
		<pubDate>Tue, 27 Oct 2009 14:15:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57077</guid>
		<description>@Sucharitha

Ideally there should be a type field instead of searching a name for the type.

If there is a list that will be managed daily, perhaps another TABLE would be best. Then the query could use a join and not have to change.</description>
		<content:encoded><![CDATA[<p>@Sucharitha</p>
<p>Ideally there should be a type field instead of searching a name for the type.</p>
<p>If there is a list that will be managed daily, perhaps another TABLE would be best. Then the query could use a join and not have to change.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sucharitha</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57067</link>
		<dc:creator>Sucharitha</dc:creator>
		<pubDate>Tue, 27 Oct 2009 12:58:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-57067</guid>
		<description>Can any one help me with such a query below.

SELECT DISTINCT Building WHERE Building IS NOT NULL
		AND Building NOT LIKE &#039;%School%&#039;
		AND Building NOT LIKE &#039;%Church%&#039;
		AND Building NOT LIKE &#039;%Rectory%&#039;
		AND Building NOT LIKE &#039;%Public House%&#039;
		AND Building NOT LIKE &#039;%Retail Park%&#039;
		AND Building NOT LIKE &#039;%Railway Station%&#039;
		AND Building NOT LIKE &#039;%Post Office%&#039;
		AND Building NOT LIKE &#039;%Court%&#039;
		AND Building NOT LIKE &#039;%Floor%&#039;
		AND Building NOT LIKE &#039;%Flat%&#039;
		AND Building NOT LIKE &#039;%Former%&#039;
		AND Building NOT LIKE &#039;%Lodge%&#039;

basically as per my requirement, the list in the not like might increase daily, I dont find the query good with the whole list as above. Is there a way I can avoid it.

Please suggest.</description>
		<content:encoded><![CDATA[<p>Can any one help me with such a query below.</p>
<p>SELECT DISTINCT Building WHERE Building IS NOT NULL<br />
		AND Building NOT LIKE &#8216;%School%&#8217;<br />
		AND Building NOT LIKE &#8216;%Church%&#8217;<br />
		AND Building NOT LIKE &#8216;%Rectory%&#8217;<br />
		AND Building NOT LIKE &#8216;%Public House%&#8217;<br />
		AND Building NOT LIKE &#8216;%Retail Park%&#8217;<br />
		AND Building NOT LIKE &#8216;%Railway Station%&#8217;<br />
		AND Building NOT LIKE &#8216;%Post Office%&#8217;<br />
		AND Building NOT LIKE &#8216;%Court%&#8217;<br />
		AND Building NOT LIKE &#8216;%Floor%&#8217;<br />
		AND Building NOT LIKE &#8216;%Flat%&#8217;<br />
		AND Building NOT LIKE &#8216;%Former%&#8217;<br />
		AND Building NOT LIKE &#8216;%Lodge%&#8217;</p>
<p>basically as per my requirement, the list in the not like might increase daily, I dont find the query good with the whole list as above. Is there a way I can avoid it.</p>
<p>Please suggest.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shrikant Patil</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-55158</link>
		<dc:creator>Shrikant Patil</dc:creator>
		<pubDate>Mon, 24 Aug 2009 12:25:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-55158</guid>
		<description>Sorry i forgot to add where value IN  in the above post . In actual &#039;m using the same query u  have return it works for small number of rows also . but when i have 90000 rows as i said above it doesnt work the way it should .</description>
		<content:encoded><![CDATA[<p>Sorry i forgot to add where value IN  in the above post . In actual &#8216;m using the same query u  have return it works for small number of rows also . but when i have 90000 rows as i said above it doesnt work the way it should .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-55127</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Sun, 23 Aug 2009 03:54:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-55127</guid>
		<description>@Shrikanth Patil.

Your first select statement is not valid. I am not sure if it could ever execute, because you are not specific about what to be search for NOT IN. 

Anyways below is a working example, consider this example and let us know if this is what you were expecting.

Example Script : 

create table #die_domain_log ( Value int identity , source_flag int , target_flag int, log_id int )

insert into #die_domain_log values ( 1, NULL , 103)
insert into #die_domain_log values ( 1, NULL , 103)
insert into #die_domain_log values ( 1, NULL , 103)
insert into #die_domain_log values ( 1, NULL , 103)
insert into #die_domain_log values ( 1, NULL , 103)

insert into #die_domain_log values (  NULL , 1, 103)
insert into #die_domain_log values (  NULL , 1, 103)
insert into #die_domain_log values (  NULL , 1, 103)
insert into #die_domain_log values (  NULL , 1, 103)
insert into #die_domain_log values (  NULL , 1, 103)


Select * from #die_domain_log 


-- Here you need to be specific what to search for NOT IN, I have include Value as a search criteria for NOT IN.

SELECT    value 
FROM       #die_domain_log 
WHERE    source_flag =1 
AND         log_id=103
AND         value 
NOT IN 
( 
SELECT     i.value 
FROM        #die_domain_log i 
WHERE     i.target_flag =1 
AND          i.log_id=103 
)

-- OR ( below is same as you posted)

SELECT value FROM #die_domain_log WHERE source_flag =1 AND log_id=103
EXCEPT
SELECT i.value FROM #die_domain_log i WHERE i.target_flag =1 AND i.log_id=103

~ IM.</description>
		<content:encoded><![CDATA[<p>@Shrikanth Patil.</p>
<p>Your first select statement is not valid. I am not sure if it could ever execute, because you are not specific about what to be search for NOT IN. </p>
<p>Anyways below is a working example, consider this example and let us know if this is what you were expecting.</p>
<p>Example Script : </p>
<p>create table #die_domain_log ( Value int identity , source_flag int , target_flag int, log_id int )</p>
<p>insert into #die_domain_log values ( 1, NULL , 103)<br />
insert into #die_domain_log values ( 1, NULL , 103)<br />
insert into #die_domain_log values ( 1, NULL , 103)<br />
insert into #die_domain_log values ( 1, NULL , 103)<br />
insert into #die_domain_log values ( 1, NULL , 103)</p>
<p>insert into #die_domain_log values (  NULL , 1, 103)<br />
insert into #die_domain_log values (  NULL , 1, 103)<br />
insert into #die_domain_log values (  NULL , 1, 103)<br />
insert into #die_domain_log values (  NULL , 1, 103)<br />
insert into #die_domain_log values (  NULL , 1, 103)</p>
<p>Select * from #die_domain_log </p>
<p>&#8211; Here you need to be specific what to search for NOT IN, I have include Value as a search criteria for NOT IN.</p>
<p>SELECT    value<br />
FROM       #die_domain_log<br />
WHERE    source_flag =1<br />
AND         log_id=103<br />
AND         value<br />
NOT IN<br />
(<br />
SELECT     i.value<br />
FROM        #die_domain_log i<br />
WHERE     i.target_flag =1<br />
AND          i.log_id=103<br />
)</p>
<p>&#8211; OR ( below is same as you posted)</p>
<p>SELECT value FROM #die_domain_log WHERE source_flag =1 AND log_id=103<br />
EXCEPT<br />
SELECT i.value FROM #die_domain_log i WHERE i.target_flag =1 AND i.log_id=103</p>
<p>~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shrikant Patil</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-55096</link>
		<dc:creator>Shrikant Patil</dc:creator>
		<pubDate>Fri, 21 Aug 2009 15:02:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-55096</guid>
		<description>Hey pinal i read your blog a lot but never commented or asked question . This is the first time . 

What i came across is this 
i have a table with around 90000 rows . 
45000 where source_flag=1 and 45000 where target_flag=1 

i was using a not in query like this 

SELECT value FROM die_domain_log WHERE source_flag =1 AND log_id=103 
NOT IN ( SELECT i.value FROM die_domain_log i WHERE i.target_flag =1 AND i.log_id=103 )

When executed it didnt returned any results for like 15-20 mins  i stoped it . 

Then i changed it to except it took less than a sec to return the result .

SELECT value FROM die_domain_log WHERE source_flag =1 AND log_id=103 
EXCEPT 
SELECT i.value FROM die_domain_log i WHERE i.target_flag =1 AND i.log_id=103

why is this happening ?</description>
		<content:encoded><![CDATA[<p>Hey pinal i read your blog a lot but never commented or asked question . This is the first time . </p>
<p>What i came across is this<br />
i have a table with around 90000 rows .<br />
45000 where source_flag=1 and 45000 where target_flag=1 </p>
<p>i was using a not in query like this </p>
<p>SELECT value FROM die_domain_log WHERE source_flag =1 AND log_id=103<br />
NOT IN ( SELECT i.value FROM die_domain_log i WHERE i.target_flag =1 AND i.log_id=103 )</p>
<p>When executed it didnt returned any results for like 15-20 mins  i stoped it . </p>
<p>Then i changed it to except it took less than a sec to return the result .</p>
<p>SELECT value FROM die_domain_log WHERE source_flag =1 AND log_id=103<br />
EXCEPT<br />
SELECT i.value FROM die_domain_log i WHERE i.target_flag =1 AND i.log_id=103</p>
<p>why is this happening ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sthish</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-53243</link>
		<dc:creator>sthish</dc:creator>
		<pubDate>Thu, 25 Jun 2009 07:13:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-53243</guid>
		<description>i want to search from the result table</description>
		<content:encoded><![CDATA[<p>i want to search from the result table</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sthish</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-53242</link>
		<dc:creator>sthish</dc:creator>
		<pubDate>Thu, 25 Jun 2009 07:12:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-53242</guid>
		<description>how to retrive the result set i want to search</description>
		<content:encoded><![CDATA[<p>how to retrive the result set i want to search</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sthish</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-53241</link>
		<dc:creator>sthish</dc:creator>
		<pubDate>Thu, 25 Jun 2009 07:11:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-53241</guid>
		<description>i am having to retrive multipul condition any one can help regading this problem.thanks for advance</description>
		<content:encoded><![CDATA[<p>i am having to retrive multipul condition any one can help regading this problem.thanks for advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerry</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-51814</link>
		<dc:creator>Jerry</dc:creator>
		<pubDate>Tue, 12 May 2009 13:08:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-51814</guid>
		<description>USE TDB;
GO
SELECT Sim_No 
FROM Sim_Record
EXCEPT
SELECT Sim 
FROM Test_in 


I need Result Drop In To  New Table</description>
		<content:encoded><![CDATA[<p>USE TDB;<br />
GO<br />
SELECT Sim_No<br />
FROM Sim_Record<br />
EXCEPT<br />
SELECT Sim<br />
FROM Test_in </p>
<p>I need Result Drop In To  New Table</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johny Bravo</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-51045</link>
		<dc:creator>Johny Bravo</dc:creator>
		<pubDate>Thu, 16 Apr 2009 15:55:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-51045</guid>
		<description>Hi Sudha
you can do this with a timestamp column, everytime record is created or update you need to update the timestamp and than to find updated rows you just need to check the timestamp in orginal and local db. 

You can also use red-gate to compare data and sql it&#039;s very good DB tool.</description>
		<content:encoded><![CDATA[<p>Hi Sudha<br />
you can do this with a timestamp column, everytime record is created or update you need to update the timestamp and than to find updated rows you just need to check the timestamp in orginal and local db. </p>
<p>You can also use red-gate to compare data and sql it&#8217;s very good DB tool.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sudha</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-48509</link>
		<dc:creator>sudha</dc:creator>
		<pubDate>Mon, 09 Mar 2009 09:50:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-48509</guid>
		<description>Hi all,
         I want to compare two  tables from two databases,where one is original database and another one is local database table.

Now,how do i compare both the tables,such  that.when compared with original database if any record or column is updated in the local database,it should return me updated records.

Using Java and SQL ,how can i do this.Please reply as earle as possible.

Thanks in Advance!!!</description>
		<content:encoded><![CDATA[<p>Hi all,<br />
         I want to compare two  tables from two databases,where one is original database and another one is local database table.</p>
<p>Now,how do i compare both the tables,such  that.when compared with original database if any record or column is updated in the local database,it should return me updated records.</p>
<p>Using Java and SQL ,how can i do this.Please reply as earle as possible.</p>
<p>Thanks in Advance!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQLAuthority News - Best Articles on SQLAuthority.com Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-47212</link>
		<dc:creator>SQLAuthority News - Best Articles on SQLAuthority.com Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Tue, 24 Feb 2009 12:08:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-47212</guid>
		<description>[...] SQL SERVER - 2005 Comparison EXCEPT operator vs. NOT IN [...]</description>
		<content:encoded><![CDATA[<p>[...] SQL SERVER &#8211; 2005 Comparison EXCEPT operator vs. NOT IN [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nandkishor Mandlik</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-44571</link>
		<dc:creator>Nandkishor Mandlik</dc:creator>
		<pubDate>Sat, 06 Dec 2008 06:57:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-44571</guid>
		<description>Hello Sir,
I used topic
&quot;17 Responses to “SQL SERVER - 2005 Comparison EXCEPT operator vs. NOT IN”&quot;of( Reeves  on July 19, 2007 at 9:57 am
  )

It helped me lot in my problem.Thanks lot.

Thank you very much.
See you again.

           Nandkishor</description>
		<content:encoded><![CDATA[<p>Hello Sir,<br />
I used topic<br />
&#8220;17 Responses to “SQL SERVER &#8211; 2005 Comparison EXCEPT operator vs. NOT IN”&#8221;of( Reeves  on July 19, 2007 at 9:57 am<br />
  )</p>
<p>It helped me lot in my problem.Thanks lot.</p>
<p>Thank you very much.<br />
See you again.</p>
<p>           Nandkishor</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: adam c</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-40486</link>
		<dc:creator>adam c</dc:creator>
		<pubDate>Sat, 19 Jul 2008 18:27:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-40486</guid>
		<description>Just wanna say thanks, found this useful. Cheers.</description>
		<content:encoded><![CDATA[<p>Just wanna say thanks, found this useful. Cheers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-40405</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Fri, 18 Jul 2008 00:57:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-40405</guid>
		<description>@compare 2 tables

I am sure there must be other ways to do this, I used a cursor and while loop, 

This can also be done with one cursor with out using a while loop, since the third column in first table contains duplicate rows, the cursor will be executed many times ( how many duplicate rows you have in column 3 in first table, that many times) I thought that would unneccarily consume performance so I chose cursor and while loop to increase performance of the query.

In short, this is also performence consuming, but I could not think of anything else,.. this is atleast a better one in my view..

Here starts your code.... 

CREATE TABLE TABLE_1 (TSID INT, TSDATE VARCHAR(10), ENAME VARCHAR(10))

INSERT INTO TABLE_1 (TSID , TSDATE, ENAME ) 
SELECT 100, &#039;7-21-2008&#039; ,&#039;NAME1&#039;UNION ALL 
SELECT 101, &#039;7-21-2008&#039;, &#039;NAME1&#039;UNION ALL 
SELECT 102, &#039;7-22-2008&#039;, &#039;NAME1&#039;UNION ALL 
SELECT 103, &#039;7-26-2008&#039;, &#039;NAME1&#039;UNION ALL 
SELECT 104, &#039;7-23-2008&#039;, &#039;NAME2&#039;UNION ALL 
SELECT 105,&#039;7-25-2008&#039;, &#039;NAME2&#039;

CREATE TABLE TABLE_2 (NODATES VARCHAR(10))

INSERT INTO TABLE_2 (NODATES) 
SELECT &#039;7-21-2008&#039;UNION ALL 
SELECT &#039;7-22-2008&#039; UNION ALL 
SELECT &#039;7-23-2008&#039;UNION ALL 
SELECT &#039;7-24-2008&#039;UNION ALL 
SELECT &#039;7-25-2008&#039;UNION ALL 
SELECT &#039;7-26-2008&#039;

We created two tables, and inserted the sample data given by you, 

I am creating two temporary tables, and then I dropped those two temporary tables at the end of the code.

SET NOCOUNT ON
DECLARE @ENAME VARCHAR(10)
DECLARE @DATE VARCHAR(10)
DECLARE @VAR INT
CREATE TABLE #RESULT ( DATE VARCHAR(10), NAME VARCHAR(10))
CREATE TABLE #TEMP1 (ID INT IDENTITY, ENAME VARCHAR(10))
INSERT INTO #TEMP1(ENAME) SELECT DISTINCT ENAME FROM TABLE_1
DECLARE @CUR CURSOR
SET @CUR = CURSOR FOR
                    SELECT DISTINCT NODATES FROM TABLE_2
OPEN @CUR
   FETCH NEXT
   FROM @CUR INTO @DATE
WHILE @@FETCH_STATUS = 0
    BEGIN
		SET @VAR = 1
		WHILE @VAR &lt; = (SELECT COUNT(1) FROM #TEMP1)
			BEGIN
				SELECT @ENAME = ENAME FROM #TEMP1 WHERE ID = @VAR
					IF  EXISTS ( SELECT TSDATE FROM TABLE_1 WHERE TSDATE = @DATE)
						BEGIN
							IF EXISTS (SELECT ENAME FROM TABLE_1 WHERE TSDATE = @DATE AND ENAME  @ENAME )
							
								BEGIN
									INSERT INTO #RESULT (DATE , NAME ) SELECT @DATE ,@ENAME 
								END
						END
					ELSE INSERT INTO #RESULT (DATE , NAME) SELECT @DATE, @ENAME
				SET @VAR = @VAR +1
			 END
	FETCH NEXT
	FROM @CUR INTO @DATE
END
CLOSE @CUR
DEALLOCATE @CUR
SELECT * FROM #RESULT ORDER BY NAME , DATE 
DROP TABLE #TEMP1
DROP TABLE #RESULT
GO

Result : 

7-23-2008	Name1
7-24-2008	Name1
7-25-2008	Name1
7-21-2008	Name2
7-22-2008	Name2
7-24-2008	Name2
7-26-2008	Name2


Hope this helps,
Thanks,
Imran.</description>
		<content:encoded><![CDATA[<p>@compare 2 tables</p>
<p>I am sure there must be other ways to do this, I used a cursor and while loop, </p>
<p>This can also be done with one cursor with out using a while loop, since the third column in first table contains duplicate rows, the cursor will be executed many times ( how many duplicate rows you have in column 3 in first table, that many times) I thought that would unneccarily consume performance so I chose cursor and while loop to increase performance of the query.</p>
<p>In short, this is also performence consuming, but I could not think of anything else,.. this is atleast a better one in my view..</p>
<p>Here starts your code&#8230;. </p>
<p>CREATE TABLE TABLE_1 (TSID INT, TSDATE VARCHAR(10), ENAME VARCHAR(10))</p>
<p>INSERT INTO TABLE_1 (TSID , TSDATE, ENAME )<br />
SELECT 100, &#8216;7-21-2008&#8242; ,&#8217;NAME1&#8242;UNION ALL<br />
SELECT 101, &#8216;7-21-2008&#8242;, &#8216;NAME1&#8242;UNION ALL<br />
SELECT 102, &#8216;7-22-2008&#8242;, &#8216;NAME1&#8242;UNION ALL<br />
SELECT 103, &#8216;7-26-2008&#8242;, &#8216;NAME1&#8242;UNION ALL<br />
SELECT 104, &#8216;7-23-2008&#8242;, &#8216;NAME2&#8242;UNION ALL<br />
SELECT 105,&#8217;7-25-2008&#8242;, &#8216;NAME2&#8242;</p>
<p>CREATE TABLE TABLE_2 (NODATES VARCHAR(10))</p>
<p>INSERT INTO TABLE_2 (NODATES)<br />
SELECT &#8216;7-21-2008&#8242;UNION ALL<br />
SELECT &#8216;7-22-2008&#8242; UNION ALL<br />
SELECT &#8216;7-23-2008&#8242;UNION ALL<br />
SELECT &#8216;7-24-2008&#8242;UNION ALL<br />
SELECT &#8216;7-25-2008&#8242;UNION ALL<br />
SELECT &#8216;7-26-2008&#8242;</p>
<p>We created two tables, and inserted the sample data given by you, </p>
<p>I am creating two temporary tables, and then I dropped those two temporary tables at the end of the code.</p>
<p>SET NOCOUNT ON<br />
DECLARE @ENAME VARCHAR(10)<br />
DECLARE @DATE VARCHAR(10)<br />
DECLARE @VAR INT<br />
CREATE TABLE #RESULT ( DATE VARCHAR(10), NAME VARCHAR(10))<br />
CREATE TABLE #TEMP1 (ID INT IDENTITY, ENAME VARCHAR(10))<br />
INSERT INTO #TEMP1(ENAME) SELECT DISTINCT ENAME FROM TABLE_1<br />
DECLARE @CUR CURSOR<br />
SET @CUR = CURSOR FOR<br />
                    SELECT DISTINCT NODATES FROM TABLE_2<br />
OPEN @CUR<br />
   FETCH NEXT<br />
   FROM @CUR INTO @DATE<br />
WHILE @@FETCH_STATUS = 0<br />
    BEGIN<br />
		SET @VAR = 1<br />
		WHILE @VAR &lt; = (SELECT COUNT(1) FROM #TEMP1)<br />
			BEGIN<br />
				SELECT @ENAME = ENAME FROM #TEMP1 WHERE ID = @VAR<br />
					IF  EXISTS ( SELECT TSDATE FROM TABLE_1 WHERE TSDATE = @DATE)<br />
						BEGIN<br />
							IF EXISTS (SELECT ENAME FROM TABLE_1 WHERE TSDATE = @DATE AND ENAME  @ENAME )</p>
<p>								BEGIN<br />
									INSERT INTO #RESULT (DATE , NAME ) SELECT @DATE ,@ENAME<br />
								END<br />
						END<br />
					ELSE INSERT INTO #RESULT (DATE , NAME) SELECT @DATE, @ENAME<br />
				SET @VAR = @VAR +1<br />
			 END<br />
	FETCH NEXT<br />
	FROM @CUR INTO @DATE<br />
END<br />
CLOSE @CUR<br />
DEALLOCATE @CUR<br />
SELECT * FROM #RESULT ORDER BY NAME , DATE<br />
DROP TABLE #TEMP1<br />
DROP TABLE #RESULT<br />
GO</p>
<p>Result : </p>
<p>7-23-2008	Name1<br />
7-24-2008	Name1<br />
7-25-2008	Name1<br />
7-21-2008	Name2<br />
7-22-2008	Name2<br />
7-24-2008	Name2<br />
7-26-2008	Name2</p>
<p>Hope this helps,<br />
Thanks,<br />
Imran.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Compare 2 tables</title>
		<link>http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-40377</link>
		<dc:creator>Compare 2 tables</dc:creator>
		<pubDate>Thu, 17 Jul 2008 11:49:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/#comment-40377</guid>
		<description>Hi i have two tables

I have to compare this 2 tables...,

Now which dates are not in table1 that date and that ename have to come in select statement 

Table1:

TSID TSdate EName
100 7-21-2008 Name1
101 7-21-2008 Name1
102 7-22-2008 Name1
103 7-26-2008 Name1
104 7-23-2008 Name2
105 7-25-2008 Name2

Table2:

Nodates
7-21-2008
7-22-2008
7-23-2008
7-24-2008
7-25-2008
7-26-2008

output:
Date Name
7-23-2008 Name1
7-24-2008 Name1
7-25-2008 Name1
7-21-2008 Name2
7-22-2008 Name2
7-24-2008 Name2
7-26-2008 Name2


how to do that</description>
		<content:encoded><![CDATA[<p>Hi i have two tables</p>
<p>I have to compare this 2 tables&#8230;,</p>
<p>Now which dates are not in table1 that date and that ename have to come in select statement </p>
<p>Table1:</p>
<p>TSID TSdate EName<br />
100 7-21-2008 Name1<br />
101 7-21-2008 Name1<br />
102 7-22-2008 Name1<br />
103 7-26-2008 Name1<br />
104 7-23-2008 Name2<br />
105 7-25-2008 Name2</p>
<p>Table2:</p>
<p>Nodates<br />
7-21-2008<br />
7-22-2008<br />
7-23-2008<br />
7-24-2008<br />
7-25-2008<br />
7-26-2008</p>
<p>output:<br />
Date Name<br />
7-23-2008 Name1<br />
7-24-2008 Name1<br />
7-25-2008 Name1<br />
7-21-2008 Name2<br />
7-22-2008 Name2<br />
7-24-2008 Name2<br />
7-26-2008 Name2</p>
<p>how to do that</p>
]]></content:encoded>
	</item>
</channel>
</rss>
