SELECT a.samAccountName
FROM activeIds AS a
WHERE NOT EXISTS (SELECT *
FROM #tmp1 AS b
WHERE a.samAccountName = b.userID)
AND a.samAccountName LIKE 'ysp%'
ORDER BY a.samAccountName ASC;
GO
I created a temp table that populates User IDs YSP0000 to YSP9999.
I have an existing table (activeIds) that is already populated with YSP IDs.
I’m trying to output YSP IDs that DON’T exist in the existing table (activeIds) already.
For some reason the YSP IDs are not displaying and other IDs (for example ZSP) appear instead.
Is there a way to make the IDs appear?
I believe what you’re looking for is not
NOT EXISTS, butNOT IN. Something like this:That will select all account names that IDs are not in the temp table.