SQL Server 2005/2008 Group By statement with parameters without using dynamic SQL?
问题 Is there a way to write SQL Server Stored Procedure which to be strongly typed ( i.e. returning known result set of columns ) and having its group statement to be dynamic. Something like: SELECT SUM( Column0 ) FROM Table1 GROUP BY @MyVar I tried the following also: SELECT SUM( Column0 ) FROM Table1 GROUP BY CASE @MyVar WHEN 'Column1' THEN Column1 ELSE Column2 The second statement works only in scenarios where the db types of Column1 and Column2 are the same. If they are not the SQL engine