Can i reuse a complex select Where clause to different group by?
What i am doing:
(Select X, Count(*) From [Big where clause with many tables] Group By X)
Union All
(Select Y, Count(*) From [Big where clause with many tables] Group By Y)
How can i optmise this?
I’m using SQL Server 2008 and this will go inside a Function, but could be a stored procedure.
CTEs were made for situations like this.