modified SearchToSQL function (2)