I tried to reproduce the problem and I can not. However, my suspicion is that βprepareβ means identifying the constant in order by , and this is a mistake. You can easily see the error using an explicit constant:
select * from information_schema.tables t order by 'a'
Error with error:
Msg 408, Level 16, State 1, Line 3 A constant expression was encountered in the ORDER BY list, position 1.
However, this works:
select *, 'a' as name from information_schema.tables t order by name;
Here is a suggestion to fix the problem. Try using a subquery:
SELECT [date], (select ?) AS [name] FROM [transactions] WHERE [category_id] = 10 GROUP BY [date] ORDER BY [date] ASC, [name] ASC;
The extra select level should convince something, somewhere your value is not a constant (and still assigns it one value).
source share