my $sthexpt = $dbhexpt->prepare("SELECT DISTINCT PAT FROM xpatentes"); $sthexpt->execute(); # Just print the values of 'pat' from the patentes table. while ( (my @row) = $sthexpt->fetchrow_array() ) { print "El nombre del proximo archivo ... E$row[0]\n"; } $sthexpt->execute(); # we've looped through all of the query results above so #-- # Create the new tables. # while ( (my @row) = $sthexpt->fetchrow_array() ) { my $tableNameexpt = "E" . $row[0]; # table names can not begin with a digit print "Creando tabla " . $tableNameexpt . "\n"; my $a_sthexpt = $dbhexpt->prepare("CREATE TABLE TableNameexpt SELECT * FROM final_exp WHERE pat = $row[0]"); $a_sthexpt->execute(); }