Is there a way to write a SQL Server stored procedure that must be strongly typed (that is, return a known set of column results) and have a dynamic expression of its group.
Sort of:
SELECT SUM( Column0 ) FROM Table1 GROUP BY @MyVar
I also tried the following:
SELECT SUM( Column0 ) FROM Table1 GROUP BY CASE @MyVar WHEN 'Column1' THEN Column1 ELSE Column2
The second statement only works in scenarios where the db types of column 1 and column 2 are the same. If they are not an SQL engine, an error occurs that says something like this: "Conversion error when converting nvarchar" SYSTEM "value to data type [The Different TYPE]."
What can I do to achieve a strong set of results and, nevertheless, have some dynamic part, that is, a group in my case? This will be displayed in LINQ.
EDIT:
It seems you can do it, but you should NOT! Absolutely bust. Testing showed numbers a thousand times slower execution plans. And it will only work more slowly with large sets of results.
source share