Added trimming to merge SQL query