modify query for sort using reg_dt