modified SearchToSQL function (3)