Fix dbexception when sorting search results by depatment name. Refs #187