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 2000 Forums
 Transact-SQL (2000)
 HowTo filter 2 selects?

Author  Topic 

KenA
Starting Member

28 Posts

Posted - 2005-11-16 : 15:58:50
Hi. Suppose I have 2 selects: select 1 and select 2

In select 1 I have a column with 3 rows and each row has the following content: cdrom, memory, clock

In select 2 I have a column with 5 rows:
cdrom, memory, clock, hd, os

Based on the 2 selects above, can I have another select statement to return only the rows that are different between those 2 selects?

In other words, just to retrieve: hd and os

»»» Ken.A

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-17 : 01:17:16
Try this
Declare @cols varchar(1000)
Select @cols=Isnull(@cols+',','')+column_name from information_schema.columns IC
where table_name='table2' and not exists
(select * from information_schema.columns where column_name=IC.column_Name and table_name='table1')
select @col2='Select ' + @cols+' from table2'
Exec(@sql)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -