public function top($sql, $qty)
    {
        if (stripos($sql, ' TOP ') === false) {
            return  preg_replace("/^\\s*(select) /i", "\\1 top $qty ", $sql);
        }

        return preg_replace(
            '~(\s[Tt][Oo][Pp])\s.*?\d+\s~',
            '$1 ' . $qty . ' ',
            $sql
        );
    }
public function top($sql, $qty)
    {
        if (stripos($sql, ' TOP ') === false) {
            return  preg_replace("/^\\s*(select) /i", "\\1 top $qty ", $sql);
        }

        return preg_replace(
            '~(\s[Tt][Oo][Pp])\s.*?\d+\s~',
            '$1 ' . $qty . ' ',
            $sql
        );
    }
public function top ( $ sql , $ qty ) { if ( stripos ( $ sql , ' TOP ' ) === false ) { return preg_replace ( "/^\\s*(select) /i" , "\\1 top $qty " , $ sql ) ; } return preg_replace ( '~(\s[Tt][Oo][Pp])\s.*?\d+\s~' , '$1 ' . $ qty . ' ' , $ sql ) ; }
Given a SQL returns it with the proper TOP or equivalent method included
@param string $sql
@param int $qty
@return string
Given a SQL returns it with the proper TOP or equivalent method included