Et CASE-udtryk skal løses til én enkelt datatype, uanset det faktum, at du ved, at @orderby kun vil vælge én gren. For at tilfredsstille den regel kan du bygge en lidt klodset, men funktionel, sortering på flere kolonner sådan:
ORDER BY CASE @orderBy WHEN 1 THEN received_date -- Last Rx'd message WHEN 2 THEN 0 WHEN 3 THEN 0 WHEN 4 THEN 0 WHEN 5 THEN ime.[allocated_date] -- Allocated Date ELSE received_date END, CASE @orderBy WHEN 1 THEN 0 WHEN 2 THEN message_id -- Message Id WHEN 3 THEN 0 WHEN 4 THEN 0 WHEN 5 THEN 0 ELSE 0 END, CASE @orderBy WHEN 1 THEN '' WHEN 2 THEN '' WHEN 3 THEN zibmat.short_name -- Message action type WHEN 4 THEN error_action.short_name -- Status type WHEN 5 THEN '' ELSE '' END