Typically when I see SQL that uses something like:
select * from employees where epmloyeeTypeId in (select id from type where name = 'emp')
I replace the where with this:
select e.* from employees e
inner join type t on t.id=e.epmloyeeTypeId and t.name = 'emp'
Is it possible to do the same with the inverse in case its is a not in (like below) instead of an in clause?
INSERT into Subscriptions(ProjectId, RecordTypeCID, NTID, Active, Added, LastUpdate, UpdateBy)
SELECT @ProjectId, RecordTypeCID, @NTID, 1, GETDATE(), GETDATE(), @NTID
FROM @Check CHK
WHERE CHK.ActiveStatus=1
And Not Exists (SELECT SubscriptionId FROM Subscriptions
WHERE ProjectId=@ProjectId
and NTID=@NTID
and RecordTypeCID = CHK.RecordTypeCID
)
Additional considerations
Can I do this:
INSERT INTO Subscriptions(ProjectId, RecordTypeCID, NTID,Active, Added, LastUpdate, UpdateBy)
SELECT @ProjectId, RecordTypeCID, @NTID,1, GETDATE(), GETDATE(), @NTID
FROM @Check CHK
LEFT JOIN Subscriptions subs ON subs.RecordTypeCID = CHK.RecordTypeCID
AND NTID = @NTID
AND ProjectId = @ProjectId
AND CHK.ActiveStatus = 1
AND subs.SubscriptionId IS NULL