FAQ Database Discussion Community


T-SQL alternatives to nested CASE for better performance?

sql-server,tsql,nested,case,sql-tuning
I have a T-SQL query that is performing very poorly to the point that it times out. The culprits are these two nested CASE statements with embedded queries: SELECT CASE WHEN b.month_type = (CASE WHEN dbo.CURRENT_BUSINESSDAY(GETDATE()) >= 8 THEN 'Current Month BD2' ELSE (CASE WHEN dbo.CURRENT_BUSINESSDAY(GETDATE()) < 8 AND (SELECT...