Conversion failed when converting date and/or time from character string
You'll need to divide your ORDER BY
into multiple CASE
statements:
ORDER BY
CASE WHEN @orderby = 0 THEN news_edits.[time] END DESC,
CASE WHEN @orderby = 1 THEN news_edits.lastedit END DESC,
CASE WHEN @orderby = 2 THEN news_edits.title END DESC
This is because single CASE
statement requires that all branches have compatible data types. Since your character string in one CASE
can't be converted to the date time returned from another CASE
, you get the conversion error.