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)
 minus operator in sqlserver

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-07-13 : 09:22:35
krishnamoorthy writes "In oracle there is a set operator minus. I am sure that we don't have any such operator in sqlserver. Is there any way to achieve the same functionality?"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-13 : 09:44:34
Refer here
http://vyaskn.tripod.com/oracle_sql_server_differences_equivalents.htm

Madhivanan

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

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-13 : 09:51:04
Think the minus operator compares resultsets and returns rows that are in the second but not in the first.

for that you would need to join on all the columns
select t1.*
from tbl1 t1
left join
tbl2 t2
on t1.col1 = t2.col1
and t1.col2 = t2.col2
...
where t2.col1 is null

you would have to deal with nulls if there are any nullable columns

this would be the equivalent of

select * from tbl1
minus
select * from tbl2


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -