Advertisement
jchaven

Find missing records that match descriptions

Nov 29th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.47 KB | None | 0 0
  1. -- find all ids and descriptions from source table that are not in destination table
  2. -- but already have a matching description in the destination table
  3. SELECT DISTINCT s.uid, s.desc
  4. FROM source_db..source_table s
  5. LEFT JOIN dest_db..dest_table d ON d.uid = s.uid
  6. WHERE s.delete_flag = 'N' AND d.uid IS NULL AND s.desc IN
  7. (
  8.     SELECT DISTINCT CONVERT(VARCHAR(MAX), t2.desc) FROM dest_db..dest_table t2
  9. );
  10.  
  11. -- note: must convert "desc" field datatype to varchar from text.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement