lundi 29 juin 2015

SQL Server LIKE clause returns only some matching rows

I'm trying to select rows from a table where there are some matching characters in the Name field. From within PHP, the where clause looks like this:

        $where = "LTRIM(RTRIM(name)) Like '%".$name."%' ";

        $sql = "SELECT name, email, Department as department, room, Telephone as telephone FROM ".$this->vcsd_tbl." WHERE ".$where." ORDER BY name ASC;";

        $statement = sqlsrv_query($this->vcsd_connection, $sql);
        $result = array();
        $index = 0;

        while ($result[$index] = sqlsrv_fetch_array($statement, SQLSRV_FETCH_ASSOC))
        {
            $index++;
        }
        return $result;

It's returning one row with a match on the name field, but it doesn't return another row that has the exact same match on the name field.

Would anyone happen to know why?

Aucun commentaire:

Enregistrer un commentaire