Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH a6
- AS ( SELECT cdc.col2
- ,maxLimit.col15
- FROM table1 AS cdc
- JOIN table2 AS cdt -- comment out this join to get seek
- ON cdt.col1 = cdc.col1
- OUTER APPLY ( SELECT TOP 1
- rules.col11
- ,rules.col15
- FROM ( SELECT clr.col11
- ,clr.col15
- ,Priority = ROW_NUMBER() OVER ( ORDER BY clr.col2 DESC, clr.col1 DESC, clr.col10 DESC, clr.col12 DESC, clr.col13 DESC, clr.col7 DESC , clr.col14 DESC )
- FROM table4 AS clr
- WHERE clr.col7 IS NULL OR clr.col7 = cdc.col7
- ) AS rules
- WHERE rules.Priority = 1
- ) maxLimit
- )
- SELECT a1.[col2] AS [col22]
- FROM [dbo].[table1] a1
- INNER JOIN [dbo].[table5] a2
- ON a1.[col2] = a2.[col2]
- INNER JOIN [dbo].[table6] a3
- ON a2.[col2] = a3.[col18]
- INNER JOIN [dbo].[table1] a4
- ON a3.[col19] = a4.[col2]
- INNER JOIN a6
- ON a6.col2 = a4.col2
- WHERE 0 < ISNULL(a6.[col15], 0)
- AND a1.col2 = '1234123412341234';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement