Sort and filter results in T-SQL