Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a query 1

Status
Not open for further replies.

TitleistDBA

IS-IT--Management
Apr 22, 2002
162
US
I have two tables that should be the same.
in FHDWHSDB.dbo.Results I have 1846191 rows
in FHECOMDB.dbo.Results I have 1846182 rows
I need to identitfy the missing 9 rows. But the query I'm trying is just not working. Can anybody help with this?


SELECT n.*
FROM FHDWHSDB.dbo.Results n
WHERE NOT EXISTS (Select *
from FHECOMDB.dbo.Results m, FHDWHSDB.dbo.Results n
WHERE m.business_Unit = n.business_unit and
m.Sales_Organization = n.Sales_Organization and
m.Order_Number = n.Order_Number and
m.Order_Suffix = n.Order_Suffix)

 
Code:
select n.*
  from FHDWHSDB.dbo.Results n
left outer
  join FHECOMDB.dbo.Results m
    on n.business_Unit      
     = m.business_unit 
   and n.Sales_Organization 
     = m.Sales_Organization 
   and n.Order_Number       
     = m.Order_Number 
   and n.Order_Suffix       
     = m.Order_Suffix 
 where m.business_unit      is null
   and m.Sales_Organization is null
   and m.Order_Number       is null
   and m.Order_Suffix       is null

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts March 6 2005)
 
One null check is all you need, isn't it? You can't join on a null can you...brain fart.
-Karl


[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top