I have a requirement to arrange the result set by column based on the Integer input in the parameter.
The problem is that I need to use CASE for OrderBy, and it seems that the code accepts the first "TYPE" in the case column ... any other types fail.
My code looks like this:
WITH error_table AS
(
SELECT Row_Number() OVER
(ORDER BY
CASE @orderBy
WHEN 1 THEN received_date
WHEN 2 THEN message_id
WHEN 3 THEN zibmat.short_name
WHEN 4 THEN error_action.short_name
WHEN 5 THEN ime.[allocated_date]
ELSE received_date
END) AS RowNumber
,ime.[ijis_message_error_id]
,ime.[message_id]
,ime.[message_version]
So, when OrderBy is 1, it works. It sorts by rx_date ... but when I sent it 2 it fails with a data time conversion error.
It looks like all types should be the same ...
Submitting 5 beautiful works, as well as date time.
Is there any way to fix this?
source
share