framework/db/mssql/QueryBuilder.php
protected function oldBuildOrderByAndLimit($sql, $orderBy, $limit, $offset)
    {
        $orderBy = $this->buildOrderBy($orderBy);
        if ($orderBy === '') {
            // ROW_NUMBER() requires an ORDER BY clause
            $orderBy = 'ORDER BY (SELECT NULL)';
        }

        $sql = preg_replace('/^([\s(])*SELECT(\s+DISTINCT)?(?!\s*TOP\s*\()/i', "\\1SELECT\\2 rowNum = ROW_NUMBER() over ($orderBy),", $sql);

        if ($this->hasLimit($limit)) {
            $sql = "SELECT TOP $limit * FROM ($sql) sub";
        } else {
            $sql = "SELECT * FROM ($sql) sub";
        }
        if ($this->hasOffset($offset)) {
            $sql .= $this->separator . "WHERE rowNum > $offset";
        }

        return $sql;
    }
protected function oldBuildOrderByAndLimit($sql, $orderBy, $limit, $offset)
    {
        $orderBy = $this->buildOrderBy($orderBy);
        if ($orderBy === '') {
            // ROW_NUMBER() requires an ORDER BY clause
            $orderBy = 'ORDER BY (SELECT NULL)';
        }

        $sql = preg_replace('/^([\s(])*SELECT(\s+DISTINCT)?(?!\s*TOP\s*\()/i', "\\1SELECT\\2 rowNum = ROW_NUMBER() over ($orderBy),", $sql);

        if ($this->hasLimit($limit)) {
            $sql = "SELECT TOP $limit * FROM ($sql) sub";
        } else {
            $sql = "SELECT * FROM ($sql) sub";
        }
        if ($this->hasOffset($offset)) {
            $sql .= $this->separator . "WHERE rowNum > $offset";
        }

        return $sql;
    }
protected function oldBuildOrderByAndLimit ( $ sql , $ orderBy , $ limit , $ offset ) { $ orderBy = $ this -> buildOrderBy ( $ orderBy ) ; if ( $ orderBy === '' ) { // ROW_NUMBER() requires an ORDER BY clause $ orderBy = 'ORDER BY (SELECT NULL)' ; } $ sql = preg_replace ( '/^([\s(])*SELECT(\s+DISTINCT)?(?!\s*TOP\s*\()/i' , "\\1SELECT\\2 rowNum = ROW_NUMBER() over ($orderBy)," , $ sql ) ; if ( $ this -> hasLimit ( $ limit ) ) { $ sql = "SELECT TOP $limit * FROM ($sql) sub" ; } else { $ sql = "SELECT * FROM ($sql) sub" ; } if ( $ this -> hasOffset ( $ offset ) ) { $ sql .= $ this -> separator . "WHERE rowNum > $offset" ; } return $ sql ; }
Builds the ORDER BY/LIMIT/OFFSET clauses for SQL SERVER 2005 to 2008.
@param string $sql the existing SQL (without ORDER BY/LIMIT/OFFSET)
@param array $orderBy the order by columns. See [[\yii\db\Query::orderBy]] for more details on how to specify this parameter.
@param int $limit the limit number. See [[\yii\db\Query::limit]] for more details.
@param int $offset the offset number. See [[\yii\db\Query::offset]] for more details.
@return string the SQL completed with ORDER BY/LIMIT/OFFSET (if any)
Builds the ORDER BY / LIMIT / OFFSET clauses for SQL SERVER 2005 to 2008 .