Hi - There is a stored procedure, that has parameters, which is in need of performance improvement. I plan to rewrite it using CTEs rather than temp tables which is how it is now. From a performance perspective, it is best to incorporate WHERE clauses in the CTEs that filter rows based on the parameter settings rather than do all of the filtering in the outer SELECT statement that references the CTEs?
For example:
--all filtering at end select a.Field1 from TableA a inner join TableB b on a.Field1 = b.Field1 where a.Field2 = @Parameter; --filtering in CTE with CTE as ( select Field1 from TableA where Field2 = @Parameter ) select a.Field1 from CTE a inner join TableB b on a.Field1 = b.Field1;