Hi @Spunny
Just to be clear, does any columns in table 2 appears in conditions of those 35 when statements?
If not ,then you can put the 35 case statement inside one CTE, and join the CTE with table2 outside.
Like this:
;WITH CTE AS
(
SELECT column1
,case
when colx = 'xxx' and coly = 'yyyy' then 'deposit'
when .......... END as description
,column2
FROM table1
)
SELECT
FROM CTE C INNER JOIN table2 T2 ON C.col3=T2.col4
If yes, then there is no need to use CTE, just current query is ok.
use CTE at the top to take care of it and left outer join main query with CTE to make it clean
Doing this might make the query look clean, but may result in higher query costs. Of course this is just my guess since you didn't provide enough information.
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.