ORDER
BY
--locationcode
CASE
@sortSetting WHEN 'DESC' THEN CASE @columnName WHEN 'locationcode' THEN fam_nm END END DESC,
CASE
@sortSetting WHEN 'ASC' THEN CASE @columnName WHEN 'locationcode' THEN fam_nm END END ASC
Note that: locationcode is the column in the target table.