# Error at convert string to integer

**URL:** <https://discourse.cakephp.org/t/error-at-convert-string-to-integer/11775>\
**Category:** Need Help\
**Created:** [January 3, 2024, 9:42am UTC](https://discourse.cakephp.org/t/error-at-convert-string-to-integer/11775 "2024-01-03T09:42:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![julito213](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@julito213](https://discourse.cakephp.org/u/julito213)\
**Post date:** [January 3, 2024, 9:42am UTC](https://discourse.cakephp.org/t/error-at-convert-string-to-integer/11775/1 "2024-01-03T09:42:08Z")

</div>

Good morning, I was developing the backend of my web application and I found this error and I don’t know how to solve it. The error is “Cannot convert value of type `string` to integer”. This is the code where I get this error.

```auto
    private function getStatusCustomerSimcards()
    {
        // Cargar el modelo de la vista
        $vStatusCustomerSimcards = TableRegistry::get('VStatusCustomerSimcards');
        // Construir la subconsulta
        $subquery = $vStatusCustomerSimcards->find();
        $subquery->select([
            'id_customer' => 'customer_orders.id_customer',
            'status_name' => 'simcard_statuses.name',
            'total_sims' => $subquery->func()->count('simcards.iccid')
        ])
            ->join([
                'simcards' => [
                    'table' => 'simcards',
                    'type' => 'INNER',
                    'conditions' => 'customer_orders.id_order = simcards.id_customer_order'
                ],
                'simcard_statuses' => [
                    'table' => 'simcard_statuses',
                    'type' => 'INNER',
                    'conditions' => 'simcards.id_simcard_status = simcard_statuses.id_simcard_status'
                ]
            ])
            ->group(['customer_orders.id_customer', 'simcard_statuses.name']);
        // Construir la consulta principal
        $query = $vStatusCustomerSimcards->find();

        $query->select([
            'id_customer',
            'total_inactive_sims' => $query->func()->sum(
                $query->newExpr()->addCase(
                    [$query->newExpr()->eq('co.status_name', 'Inactive')],
                    ['co.total_sims'],
                    ['integer']

                )
            ),
            'total_test_sims' => $query->func()->sum(
                $query->newExpr()->addCase(
                    [$query->newExpr()->eq('co.status_name', 'Test')],
                    ['co.total_sims'],
                    ['integer']

                )
            ),
            'total_activation_ready_sims' => $query->func()->sum(
                $query->newExpr()->addCase(
                    [$query->newExpr()->eq('co.status_name', 'Activation Ready')],
                    ['co.total_sims'],
                    ['integer']

                )
            ),
            'total_active_sims' => $query->func()->sum(
                $query->newExpr()->addCase(
                    [$query->newExpr()->eq('co.status_name', 'Active')],
                    ['co.total_sims'],
                    ['integer']

                )
            ),
            'total_suspended_sims' => $query->func()->sum(
                $query->newExpr()->addCase(
                    [$query->newExpr()->eq('co.status_name', 'Suspended')],
                    ['co.total_sims'],
                    ['integer']

                )
            ),
            'total_deactivated_sims' => $query->func()->sum(
                $query->newExpr()->addCase(
                    [$query->newExpr()->eq('co.status_name', 'Deactivated')],
                    ['co.total_sims'],
                    ['integer']

                )
            ),
            'total_cooldown_sims' => $query->func()->sum(
                $query->newExpr()->addCase(
                    [$query->newExpr()->eq('co.status_name', 'Cooldown')],
                    ['co.total_sims'],
                    ['integer']

                )
            ),
        ])
            ->from(['co' => $subquery])
            ->group(['id_customer']);

        try {
            $results = $query->all(); // Ejecutar la consulta y obtener los resultados
            return $results; // Devolver los resultados
        } catch (Exception $error) {
            // Manejar la excepción
            $this->Flash->error(__('Error al obtener el estado de las SIMs de los clientes: ' . $error->getMessage()));
            return [];
        }
    }

```

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [January 3, 2024, 12:59pm UTC](https://discourse.cakephp.org/t/error-at-convert-string-to-integer/11775/2 "2024-01-03T12:59:22Z")

</div>

A stacktrace would be nice.

But the error message `Cannot convert value of type string to integer` indicates you have data inside your table/column you are selecting which you are expecting to be an integer but it actually isn’t.

So maybe try to [enable SQL Logging](https://book.cakephp.org/4/en/orm/database-basics.html#query-logging) or try `debug($query->sql())` and execute that SQL directly inside a SQL CLI, PHPMyAdmin or wherever you like to execute sql.
