Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. select top 0 * into #tmpProcessingListItem from [LINK_QUEUE_ITEM]
  2.  
  3. if (@OrderByImportanceScore = 1)
  4. BEGIN
  5. insert into #tmpProcessingListItem
  6. SELECT TOP (@MaxResults) *
  7. FROM [LINK_QUEUE_ITEM] with(readpast)
  8. where 1 = 1
  9. and ([ITEM_TYPE] = @ItemType)
  10. and (isnull(@FromDB, '') = '' or FROM_DB = @FromDB)
  11. and (isnull(@ToDB, '') = '' or TO_DB = @ToDB)
  12. and ([STATUS_ID] > 0)
  13. and (ISNULL(@Action, '') = '' or [ACTION] = @Action)
  14. and (ISNULL(@ImportanceScore, 0) = 0 or IMPORTANCE_SCORE = @ImportanceScore)
  15. and (ISNULL(@FromDataset, '') = '' or FROM_DATASET = @FromDataset)
  16. and (ISNULL(@FromType, 0) = 0 or FROM_TYPE = @FromType)
  17. and (@from =0 or FROM_ID in (select OBJECT_ID from #TMP_CoreLinking_IDList))
  18. and (ISNULL(@ToDataset, '') = '' or TO_DATASET = @ToDataset)
  19. and (@from =1 or TO_ID in (select OBJECT_ID from #TMP_CoreLinking_IDList))
  20. and (ISNULL(@ToType, 0) = 0 or TO_TYPE = @ToType)
  21. and (ISNULL(@LockedBy, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000' or LOCKED_BY = @LockedBy)
  22. and (@OnlyUnlocked = 0 or ISNULL(LOCKED_BY, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000')
  23. order by [IMPORTANCE_SCORE] DESC
  24. END
  25. ELSE
  26. BEGIN
  27. IF (@from = 1)
  28. BEGIN
  29. insert into #tmpProcessingListItem
  30. SELECT TOP (@MaxResults) *
  31. FROM LINK_QUEUE_ITEM with(index(IX_ITEM_TYPE_ACTIVE), forceseek, readpast)
  32. where 1 = 1
  33. and ([ITEM_TYPE] = @ItemType)
  34. and FROM_ID in (select OBJECT_ID from #TMP_CoreLinking_IDList)
  35. and (isnull(@FromDB, '') = '' or FROM_DB = @FromDB)
  36. and (isnull(@ToDB, '') = '' or TO_DB = @ToDB)
  37. and ([STATUS_ID] > 0)
  38. and (isnull(@Action, '') = '' or [ACTION] = @Action)
  39. and (isnull(@ImportanceScore, 0) = 0 or IMPORTANCE_SCORE = @ImportanceScore)
  40. and (isnull(@FromDataset, '') = '' or FROM_DATASET = @FromDataset)
  41. and (isnull(@FromType, 0) = 0 or FROM_TYPE = @FromType)
  42. and (isnull(@ToDataset, '') = '' or TO_DATASET = @ToDataset)
  43. and (isnull(@ToType, 0) = 0 or TO_TYPE = @ToType)
  44. and (ISNULL(@LockedBy, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000' or LOCKED_BY = @LockedBy)
  45. and (@OnlyUnlocked = 0 or ISNULL(LOCKED_BY, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000')
  46. END
  47. ELSE
  48. BEGIN
  49. insert into #tmpProcessingListItem
  50. SELECT TOP (@MaxResults) *
  51. FROM LINK_QUEUE_ITEM with(index(IX_ITEM_TYPE_ACTIVE), forceseek, readpast)
  52. where 1 = 1
  53. and ([ITEM_TYPE] = @ItemType)
  54. and TO_ID in (select OBJECT_ID from #TMP_CoreLinking_IDList)
  55. and (isnull(@FromDB, '') = '' or FROM_DB = @FromDB)
  56. and (isnull(@ToDB, '') = '' or TO_DB = @ToDB)
  57. and ([STATUS_ID] > 0)
  58. and (isnull(@Action, '') = '' or [ACTION] = @Action)
  59. and (isnull(@ImportanceScore, 0) = 0 or IMPORTANCE_SCORE = @ImportanceScore)
  60. and (isnull(@FromDataset, '') = '' or FROM_DATASET = @FromDataset)
  61. and (isnull(@FromType, 0) = 0 or FROM_TYPE = @FromType)
  62. and (isnull(@ToDataset, '') = '' or TO_DATASET = @ToDataset)
  63. and (isnull(@ToType, 0) = 0 or TO_TYPE = @ToType)
  64. and (ISNULL(@LockedBy, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000' or LOCKED_BY = @LockedBy)
  65. and (@OnlyUnlocked = 0 or ISNULL(LOCKED_BY, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000')
  66. END
  67. END
  68.  
  69.  
  70. SELECT * FROM #tmpProcessingListItem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement