Skip to content
Advertisement

SQL Case Order By specific order and Direction

I have a table that I need sorted on fields By @SortBy and @SortDirection,

for ID,PriorityID,stateType (column type is int) result is OK, but for Title (nvarchar) Query Result is:

Conversion failed when converting the nvarchar value 'Title Column value' to data type int.

Query:

Advertisement

Answer

The types are different, and that is a problem for the case expressions. The simplest method is a different case for each possibility:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement