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 2005 Forums
 Transact-SQL (2005)
 Compare 2 tables

Author  Topic 

Mageshkumar
Starting Member

29 Posts

Posted - 2008-07-17 : 07:59:30
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

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-07-17 : 08:11:23
Here's one way...

select * from (select distinct EName from Table1) a cross join Table2 b
where not exists (select * from Table1 where TSdate = b.TSdate and EName = a.EName)


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

Mageshkumar
Starting Member

29 Posts

Posted - 2008-07-17 : 08:26:58
Thank u RyanRandall...,

Thanks lot
Go to Top of Page
   

- Advertisement -