Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. declare @targetdate datetime;
  2. set @targetdate = DATEADD(yy, -3, GETDATE())
  3. declare @contacts table (contactid int);
  4. declare @protectedorgcontacts table (contactid int);
  5. declare @protectedprjcontacts table (contactid int);
  6. declare @orphancontacts table (contactid int);
  7. declare @gdprset table (projectid int,orgid int);
  8. insert into @gdprset
  9. select projectid,ORGID from prj
  10. WHERE PRJ.RECEIVEDDATE <= @targetdate AND (PRJ.STATUSCURRENT = 800100400 OR PRJ.STATUSCURRENT = 800100050);
  11.  
  12. insert into @protectedorgcontacts select contactid from oco where ORGID not in (select orgid from @gdprset);
  13. insert into @protectedprjcontacts select contactid from PCO where PROJECTID not in (select projectid from @gdprset);
  14. insert into @orphancontacts select contactid from con where CONTACTID not in (select contactid from oco) and CONTACTID not in (select CONTACTID from pco);
  15.  
  16. insert into @contacts select contactid from con
  17. where CONTACTID not in (select contactid from @protectedorgcontacts)
  18. and CONTACTID not in (select contactid from @protectedprjcontacts)
  19. and contactid not in (select contactid from @orphancontacts);
  20. select * from @contacts;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement