Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. SELECT I.UnitId
  2. FROM #Inserts AS I
  3. WHERE NOT EXISTS (
  4. SELECT 1
  5. from #Inserts AS INS
  6. INNER JOIN Organisation AS O
  7. ON INS.OrganisationId = O.OrganisationId
  8. AND INS.UnitId = O.UnitId
  9. )
  10.  
  11. DELETE INS FROM #Inserts AS INS
  12. INNER JOIN Organisation AS O
  13. ON INS.OrganisationId = O.OrganisationId
  14. AND INS.UnitId = O.UnitId
  15.  
  16. SELECT I.UnitId
  17. FROM #Inserts I
  18. WHERE NOT EXISTS (SELECT 1
  19. FROM Organisation AS O
  20. WHERE I.OrganisationId = O.OrganisationId AND I.UnitId = O.UnitId
  21. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement