Roman78 Roman78 - 1 year ago 66
SQL Question

SQL Query combine two tables on existing of data

Short: I want to check if a certain cell value exist in another table.

Long: We have an old MS-SQL 2000 server and a some newer SQL Server 2012. And we importing data from the old to the new one. Herefor we copy the old tables and convert those an put the values into the Item Ledger Entry Table. And we have a "check" table, containing the data already read into the Item Ledger Table.

Now we had some issues whit those copying and there are entries in the "check" Table of data that is not in the Item Ledger Entry Table. So we are missing some Data.

So I did a test and if I remove the entry from the Check Table and start an new import, the data is being copied to the Item Ledger Entry Table. So now I have to check for data that is in the Check Table but not in the Item Ledger Entry Table. Good thing is that we have one Primary-key, [No_] in the Check table and [Document No_] in the Item Ledger Entry table. And we have a time scale, started 19 November.

But how do I put that into a query? Must be something like this

select *
from [Check Table]
where No_ "does not exist in cell [Document No_] in Item Ledger Entry"

Answer Source
Select Chk.* 
From [Check table] as chk Left Join [Item Ledger Entry table] as ItmLgr
On chk.[No_]=ItmLgr.[Document No_]
Where ItmLgr.[Document No_] is null
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download