Just add the CASE construct to your SELECT. The CASE construct can be made more compact too:
select distinct VacancyInternalID
,VacancyTitle
,null ParentInternalID
,null GeoLocation
,
order = (
case @SortFieldIndexConfig
when 2
then 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 '%%'
order by (
case @SortFieldIndexConfig
when 2
then VacancyTitle
else VacancyInternalID
end
) desc
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.