I am trying to create dynamically named MySQL tables in routines using a prefix based on a model run number which I set in php as the `@ModelRef` variable.

I can usually create the tables no problem but sometimes the routine crashes when trying to write data to the newly created table. The following code works:

```
SET @TableName = CONCAT('`',@ModelRef, '_', 'input_actual_php','`');

SET @Table_Text:=CONCAT('CREATE TABLE IF NOT EXISTS ',@TableName, ' (
    case_id                 INT PRIMARY KEY DEFAULT 1,
    Savings1                DECIMAL(10,2) DEFAULT NULL,
    Savings2                DECIMAL(10,2) DEFAULT NULL,
    TermDeposit             DECIMAL(10,2) DEFAULT NULL,
    FC_Dist                 INT DEFAULT NULL)'

    );

    PREPARE stmt from @Table_Text;
    EXECUTE stmt;   

-- Write values to table
    SET @TableEdit:=CONCAT('INSERT INTO ',@TableName,' VALUES
        (case_id, @Savings1, @Savings2, @TermDeposit, @FC_Dist)');

    PREPARE stmt from @TableEdit;
    EXECUTE stmt;   

```

and yet the following code in a different routine does not:

```
SET @TableName_1 = CONCAT('`', @ModelRef, '_lookup_wage_growth','`');

SET @Table_Text_1:=CONCAT('CREATE TABLE IF NOT EXISTS ',@TableName_1, ' (
    Age INT PRIMARY KEY DEFAULT 0,
    ModYear INT DEFAULT 0,
    Growth_1 DECIMAL(5 , 3 ) DEFAULT 0,
    GrowthInd_1 DECIMAL(5 , 3 ) DEFAULT 0,
    NomWage_1 INT DEFAULT 0,
    NomWage_1_UD INT DEFAULT 0)'
);

PREPARE stmt from @Table_Text_1;
EXECUTE stmt; 

-- Code here doing calculations and generating values

-- Write to table
        SET @TableEdit_1:=CONCAT('INSERT INTO ',@TableName_1,' VALUES
            (age_var, ModYear_var, Growth_1_var, GrowthInd_1_var, NomWage_1_var, @NomWage_1_UD)'); 

        PREPARE stmt from @TableEdit_1;
        EXECUTE stmt;

```

I have tried and played with different variations of above and simplified everything and yet I can't work out why the second routine fails to write to the table and crash. Is there something I am missing??