SELECT id FROM tableAEXCEPT SELECT ClientId FROM tableBSELECT id FROM tableA a LEFT JOIN tableB b ON b.ClientID = a.idWHERE b.id is null
(A UNION B) EXCEPT (A INTERSECT B)
A AND (NOT B)
SET NOCOUNT ON--=======================================================================================-- Recursive method shown by (Name with-held)--======================================================================================= PRINT '========== Recursive method =========='--===== Turn on some performance counters =============================================== SET STATISTICS IO ON SET STATISTICS TIME ONDECLARE @BitBucket DATETIME --Holds display output so display times aren't measured.--===== Execute the code being tested ===================================================DECLARE @DateVal DATETIME SET @DateVal = '2008-01-01';with mycte as ( select @DateVal AS DateVal union all select DateVal + 1 from mycte where DateVal + 1 < DATEADD(yy, 5, @DateVal) )select @BitBucket = d.datevalfrom mycte dOPTION (MAXRECURSION 0)--===== Turn off the performance counters and print a separator ========================= SET STATISTICS TIME OFF SET STATISTICS IO OFF PRINT REPLICATE('=',90)GO--=======================================================================================-- Tally table method by Jeff Moden--======================================================================================= PRINT '========== Tally table method =========='--===== Turn on some performance counters =============================================== SET STATISTICS IO ON SET STATISTICS TIME ONDECLARE @BitBucket DATETIME --Holds display output so display times aren't measured.--===== Execute the code being tested ===================================================DECLARE @StartDate AS DATETIME SET @StartDate = '2008-01-01'SELECT TOP (DATEDIFF(dd,@StartDate,DATEADD(yy,5,@StartDate))) @BitBucket = @StartDate-1+t.N FROM Tally t ORDER BY N--===== Turn off the performance counters and print a separator ========================= SET STATISTICS TIME OFF SET STATISTICS IO OFF PRINT REPLICATE('=',90)