src/Sqlsrv/SqlsrvDriver.php
protected function limit($sql, $limit, $offset)
	{
		$orderBy = stristr($sql, 'ORDER BY');

		if ($orderBy === null || empty($orderBy))
		{
			$orderBy = 'ORDER BY (select 0)';
		}

		$sql = str_ireplace($orderBy, '', $sql);

		$rowNumberText = ',ROW_NUMBER() OVER (' . $orderBy . ') AS RowNumber FROM ';

		$sql = preg_replace('/\\s+FROM/', '\\1 ' . $rowNumberText . ' ', $sql, 1);
		$sql = 'SELECT TOP ' . $this->limit . ' * FROM (' . $sql . ') _myResults WHERE RowNumber > ' . $this->offset;

		return $sql;
	}
protected function limit($sql, $limit, $offset)
	{
		$orderBy = stristr($sql, 'ORDER BY');

		if ($orderBy === null || empty($orderBy))
		{
			$orderBy = 'ORDER BY (select 0)';
		}

		$sql = str_ireplace($orderBy, '', $sql);

		$rowNumberText = ',ROW_NUMBER() OVER (' . $orderBy . ') AS RowNumber FROM ';

		$sql = preg_replace('/\\s+FROM/', '\\1 ' . $rowNumberText . ' ', $sql, 1);
		$sql = 'SELECT TOP ' . $this->limit . ' * FROM (' . $sql . ') _myResults WHERE RowNumber > ' . $this->offset;

		return $sql;
	}
protected function limit ( $ sql , $ limit , $ offset ) { $ orderBy = stristr ( $ sql , 'ORDER BY' ) ; if ( $ orderBy === null || empty ( $ orderBy ) ) { $ orderBy = 'ORDER BY (select 0)' ; } $ sql = str_ireplace ( $ orderBy , '' , $ sql ) ; $ rowNumberText = ',ROW_NUMBER() OVER (' . $ orderBy . ') AS RowNumber FROM ' ; $ sql = preg_replace ( '/\\s+FROM/' , '\\1 ' . $ rowNumberText . ' ' , $ sql , 1 ) ; $ sql = 'SELECT TOP ' . $ this -> limit . ' * FROM (' . $ sql . ') _myResults WHERE RowNumber > ' . $ this -> offset ; return $ sql ; }
Method to wrap an SQL statement to provide a LIMIT and OFFSET behavior for scrolling through a result set.

@param   string   $sql     The SQL statement to process.
@param   integer  $limit   The maximum affected rows to set.
@param   integer  $offset  The affected row offset to set.

@return  string   The processed SQL statement.

@since   1.0
Method to wrap an SQL statement to provide a LIMIT and OFFSET behavior for scrolling through a result set .