Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare @targetdate datetime;
- set @targetdate = DATEADD(yy, -3, GETDATE())
- declare @contacts table (contactid int);
- declare @protectedorgcontacts table (contactid int);
- declare @protectedprjcontacts table (contactid int);
- declare @orphancontacts table (contactid int);
- declare @gdprset table (projectid int,orgid int);
- insert into @gdprset
- select projectid,ORGID from prj
- WHERE PRJ.RECEIVEDDATE <= @targetdate AND (PRJ.STATUSCURRENT = 800100400 OR PRJ.STATUSCURRENT = 800100050);
- insert into @protectedorgcontacts select contactid from oco where ORGID not in (select orgid from @gdprset);
- insert into @protectedprjcontacts select contactid from PCO where PROJECTID not in (select projectid from @gdprset);
- insert into @orphancontacts select contactid from con where CONTACTID not in (select contactid from oco) and CONTACTID not in (select CONTACTID from pco);
- insert into @contacts select contactid from con
- where CONTACTID not in (select contactid from @protectedorgcontacts)
- and CONTACTID not in (select contactid from @protectedprjcontacts)
- and contactid not in (select contactid from @orphancontacts);
- select * from @contacts;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement