Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. CREATE PROCEDURE {databaseOwner}[{objectQualifier}avtSearchBoost_RemoveQueueDuplicates]
  2. AS
  3. BEGIN
  4. IF NOT EXISTS (SELECT * FROM {databaseOwner}[{objectQualifier}avtSearchBoost_IndexingQueue])
  5. RETURN
  6.  
  7. DELETE table1
  8. FROM {databaseOwner}[{objectQualifier}avtSearchBoost_IndexingQueue] AS table1
  9. WHERE (table1.[Due] < ( select max([Due]) from {databaseOwner}[{objectQualifier}avtSearchBoost_IndexingQueue] where [ItemId] = table1.[ItemId] AND [InstanceId] = table1.[InstanceId] AND (CharIndex('remove',[Action]) = 1)))
  10. AND (CharIndex('remove',table1.[Action]) = 1);
  11.  
  12. DELETE table1
  13. FROM {databaseOwner}[{objectQualifier}avtSearchBoost_IndexingQueue] AS table1
  14. WHERE (table1.[Due] < ( select max([Due]) from {databaseOwner}[{objectQualifier}avtSearchBoost_IndexingQueue] where [ItemId] = table1.[ItemId] AND [InstanceId] = table1.[InstanceId] AND (CharIndex('add',[Action]) = 1)))
  15. AND (CharIndex('add',table1.[Action]) = 1);
  16.  
  17. WITH CTE AS(
  18. SELECT [Action]
  19. ,[ItemId]
  20. ,[InstanceId]
  21. ,[Due]
  22. ,RN = ROW_NUMBER()OVER(PARTITION BY [Action]
  23. ,[ItemId]
  24. ,[InstanceId]
  25. ,[Due] ORDER BY [Due])
  26. FROM {databaseOwner}[{objectQualifier}avtSearchBoost_IndexingQueue]
  27. )
  28. DELETE FROM CTE WHERE RN > 1
  29. END
  30. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement