• You could use Phil's suggested query as a subquery. This lets you add as many CASE statements with as many WHEN statements as you want and it lets you filter out those unwanted columns in the final query result. The following code should give you an idea of what I mean. Obviously the OrderBy2 part would not have the same syntax as OrderBy1.

    SELECT

    sub.VacancyInternalID

    ,sub.VacancyTitle

    ,sub.ParentInternalID

    ,sub.GeoLocation

    FROM

    (

    select distinct VacancyInternalID

    ,VacancyTitle

    ,null ParentInternalID

    ,null GeoLocation

    ,OrderBy1= (

    case @SortFieldIndexConfig

    when 1then VacancyInternalID

    when 2then VacancyTitle

    else VacancyInternalID

    end

    )

    ,OrderBy2= (

    case @SortFieldIndexConfig

    when 1then VacancyInternalID

    when 2then VacancyTitle

    else VacancyInternalID

    end

    )

    from Vacancy.TB_Vacancy va

    inner join Config.TB_Contract co on va.VacancyContractID = co.ContractInternalID

    where co.ContractExternalID = '492A94D0-7D71-46E5-A8F6-E3A973394647'

    and co.ContractStatusID = 1

    and VacancyStatusID = 1

    and VacancyTitle like '%%'

    ) sub

    ORDER BY sub.OrderBy1 DESC, sub.OrderBy2 DESC