Tuesday, 2 February 2021

AX365/2012 X++ SQL select statement inside AX

 

  Connection      connection;

        Statement       statement;

        str             query;

        Resultset       resultSet;

        container conComm;

        ;


        // create connection object

        connection = new Connection();


        // create statement

        statement = connection.createStatement();


        // Set the SQL statement

        query = "select ACQUISITIONPRICE,BookID,BookType,Status from AssetBookMerge where AssetID = '" + strAssetId + "'";


        // assert SQL statement execute permission

        new SqlStatementExecutePermission(query).assert();


        // when the query returns result,

        // loop all results for processing

        //BP Deviation documented

        resultSet = statement.executeQuery(query);


        while(resultSet.next())

        {

            // do something with the result

            conComm =[resultSet.getString(1),resultSet.getString(2),resultSet.getString(3),resultSet.getString(4)] ;

        }


        // limit the scope of the assert call

        CodeAccessPermission::revertAssert();

        return conComm;

No comments:

Post a Comment