Home Forums Programming General Changing code within a Select statement RE: Changing code within a Select statement

  • I didn't test it, but I guess you could try to see if this works:

    GROUP BY MonthKey, CASE WHEN @Parm1 = 2 THEN CorporateName END

    I do not expect this to perform very well though. Dynamic SQL or repeating the query (preferably in separate stored procedures that are called from a master stored procedure) will almost certainly perform better.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/