Get ids not in table from large list of ids
11:14 25 Jun 2015

I have a large list of IDs that I need to check against a table to see which ones are not in my table.

I wrote this query:

SELECT id 
FROM ( VALUES (1,2,3,4...) AS Checking (id)
       WHERE id NOT IN (SELECT UniqueActivityID 
                          FROM UserActivity
                         WHERE CONVERT(DATE,[Date]) > CONVERT(DATE,'2015-06-24')
     )

The problem is that the query times out because of the large amount of numbers (20'000) and/or table size (+2 million rows). Can I do this in a better, less demanding way?

sql sql-server t-sql query-optimization