Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Write output to Access database

    Posted 08/15/09 12:20 AM

    Originally posted by: SystemAdmin


    [Boon said:]

    Hello,

    In the .dat file, I have a code like this.

    DBExecute(db1,TempOutput);
    DBExecute(db1,"create table " & TempOutput & "(LaneID r.....


    I am thinking about using a variable TempOutput as a input for the table name. I declared string TempOutput="Result"; in the .mod file. Can I do this?

    I am trying to make it possible for a user to put in a table name in the .mod file.

    Thanks,
    Boon



    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Write output to Access database

    Posted 08/15/09 08:42 AM

    Originally posted by: SystemAdmin


    [Boon said:]

    OK, just figured it out.

    Declare variable in .mod file like this ....   

    string Output= "Create table " + TableName + "(ID real,.........)"


    Now my next problem.Normally, I drop a table, create a table, and update the result like this...

    DBExecute(db,"drop table Result");
    DBExecute(db,"create table Result(oil varchar(10), gas varchar(10), blend real, a real)");
    Result to DBUpdate(db,"INSERT INTO Result(oil,gas,blend,a) VALUES(?,?,?,?)");


    The problem is if I don't have a table Result already exists in the database, this code would give me an error. (I notice that I don't see error when I ran in OPL. It just gave me a warning and seems to be working fine. But, It didn't work when I use oplrun in command line. It stucked at the drop table error and stopped the process.)

    What I want to do is --> if there is no table Result in the database, then create it. If there is table Result in the database already, just replace it. (note that I need to create a new table because sometimes a user can arbitrary choose a table name.)

    Thank you!



    #DecisionOptimization
    #OPLusingCPLEXOptimizer