This is an extract sql that gets days
AND S.Date IN
(
SELECT Date
FROM
(
SELECT Date,
ROW_NUMBER() OVER (ORDER BY Date DESC )-1 Day
FROM CALENDAR_DIM
WHERE TYPE = 'ABC'
)
WHERE BUS_DAY BETWEEN 0 AND 2
)
I want to run this code twice in two parts of my sql. How can i do that without pasting the same code. Also .. how could i rewrite the above code?. I am having some issues with performance.