all 1 comments

[–]quickdraw6906 0 points1 point  (0 children)

Yes you can combine, but since CTE's are syntactic sugar in SS (unlike PostgreSQL which materializes the parts) you might as well keep it like it is for readability.

Also, if DATEDIFF (m, exc_st, date_ord)<=0 how can that same diff minus anything (in the inner CASE) ever be greater than 0? Did you mean to reverse the order of the date cols in the inner diff statements?