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;
	}