Solved the problem. Thank you all for your time in responding.
I leave the script of the model for those who need it.
Now works with a mssql database connection
Note: The table structure was kept the same as it was in excel and an unpivot statement had to be used when extracting the data from the table because cplex works it in rows. Another thing that must be highlighted is that unlike the connection to Excel, when the connection is with a database, you cannot define the number of rows and columns in advance, but this is done at the same time that the data is extracted from the table.
//Table mssql (version cplex 12.6.3 or lower since higher versions have another database access syntax)
// mod
{int} Weeks= ...;
{int} Movies= ...;
//Load data from table mssql
float WeekDemand[Movies][Weeks] = ...;
float expDemand [Movies][Weeks];
dvar boolean k[Movies][Weeks];
execute Demand{
for(var w in Weeks)
for(var m in Movies)
expDemand[m][w] = WeekDemand[m][w]*2.25;
}
dexpr float Objective =
sum(m in Movies, w in Weeks)
(expDemand[m][w]*k[m][w]);
maximize Objective;
subject to{
}
tuple Cinema{
int mm;
int ww;
int value;
}
{Cinema} FilmSet = {<a,b,k[a][b]> | a in Movies, b in Weeks};
// dat
DBConnection db("oledb","user/password/name_database/HOST\\INSTANCE_NAME");
Movies,Weeks,WeekDemand from DBRead(db,"SELECT id_movie, cast(weeks As int), demandas FROM demand UNPIVOT ( demandas FOR [weeks] IN ([1], [2], [3], [4])) AS P");
FilmSet to DBUpdate(db,"INSERT INTO result(id_movie,week,demand) VALUES(?,?,?)");
Good luck to everyone !!!
------------------------------
MIGUEL FLORES QUISPE
------------------------------