Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select top 0 * into #tmpProcessingListItem from [LINK_QUEUE_ITEM]
- if (@OrderByImportanceScore = 1)
- BEGIN
- insert into #tmpProcessingListItem
- SELECT TOP (@MaxResults) *
- FROM [LINK_QUEUE_ITEM] with(readpast)
- where 1 = 1
- and ([ITEM_TYPE] = @ItemType)
- and (isnull(@FromDB, '') = '' or FROM_DB = @FromDB)
- and (isnull(@ToDB, '') = '' or TO_DB = @ToDB)
- and ([STATUS_ID] > 0)
- and (ISNULL(@Action, '') = '' or [ACTION] = @Action)
- and (ISNULL(@ImportanceScore, 0) = 0 or IMPORTANCE_SCORE = @ImportanceScore)
- and (ISNULL(@FromDataset, '') = '' or FROM_DATASET = @FromDataset)
- and (ISNULL(@FromType, 0) = 0 or FROM_TYPE = @FromType)
- and (@from =0 or FROM_ID in (select OBJECT_ID from #TMP_CoreLinking_IDList))
- and (ISNULL(@ToDataset, '') = '' or TO_DATASET = @ToDataset)
- and (@from =1 or TO_ID in (select OBJECT_ID from #TMP_CoreLinking_IDList))
- and (ISNULL(@ToType, 0) = 0 or TO_TYPE = @ToType)
- and (ISNULL(@LockedBy, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000' or LOCKED_BY = @LockedBy)
- and (@OnlyUnlocked = 0 or ISNULL(LOCKED_BY, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000')
- order by [IMPORTANCE_SCORE] DESC
- END
- ELSE
- BEGIN
- IF (@from = 1)
- BEGIN
- insert into #tmpProcessingListItem
- SELECT TOP (@MaxResults) *
- FROM LINK_QUEUE_ITEM with(index(IX_ITEM_TYPE_ACTIVE), forceseek, readpast)
- where 1 = 1
- and ([ITEM_TYPE] = @ItemType)
- and FROM_ID in (select OBJECT_ID from #TMP_CoreLinking_IDList)
- and (isnull(@FromDB, '') = '' or FROM_DB = @FromDB)
- and (isnull(@ToDB, '') = '' or TO_DB = @ToDB)
- and ([STATUS_ID] > 0)
- and (isnull(@Action, '') = '' or [ACTION] = @Action)
- and (isnull(@ImportanceScore, 0) = 0 or IMPORTANCE_SCORE = @ImportanceScore)
- and (isnull(@FromDataset, '') = '' or FROM_DATASET = @FromDataset)
- and (isnull(@FromType, 0) = 0 or FROM_TYPE = @FromType)
- and (isnull(@ToDataset, '') = '' or TO_DATASET = @ToDataset)
- and (isnull(@ToType, 0) = 0 or TO_TYPE = @ToType)
- and (ISNULL(@LockedBy, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000' or LOCKED_BY = @LockedBy)
- and (@OnlyUnlocked = 0 or ISNULL(LOCKED_BY, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000')
- END
- ELSE
- BEGIN
- insert into #tmpProcessingListItem
- SELECT TOP (@MaxResults) *
- FROM LINK_QUEUE_ITEM with(index(IX_ITEM_TYPE_ACTIVE), forceseek, readpast)
- where 1 = 1
- and ([ITEM_TYPE] = @ItemType)
- and TO_ID in (select OBJECT_ID from #TMP_CoreLinking_IDList)
- and (isnull(@FromDB, '') = '' or FROM_DB = @FromDB)
- and (isnull(@ToDB, '') = '' or TO_DB = @ToDB)
- and ([STATUS_ID] > 0)
- and (isnull(@Action, '') = '' or [ACTION] = @Action)
- and (isnull(@ImportanceScore, 0) = 0 or IMPORTANCE_SCORE = @ImportanceScore)
- and (isnull(@FromDataset, '') = '' or FROM_DATASET = @FromDataset)
- and (isnull(@FromType, 0) = 0 or FROM_TYPE = @FromType)
- and (isnull(@ToDataset, '') = '' or TO_DATASET = @ToDataset)
- and (isnull(@ToType, 0) = 0 or TO_TYPE = @ToType)
- and (ISNULL(@LockedBy, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000' or LOCKED_BY = @LockedBy)
- and (@OnlyUnlocked = 0 or ISNULL(LOCKED_BY, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000')
- END
- END
- SELECT * FROM #tmpProcessingListItem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement