Showing posts with label MS Dynamic AX. Show all posts
Showing posts with label MS Dynamic AX. Show all posts

Thursday, September 14, 2017

Container and unbounded string fields are not allowed in a WHERE expression.

I had a requirement to store huge data of xml into AX table i.e. I used string size as [MEMO].
Response1, Response2 & Response3 are Memo Fields.

Now my requirement is to perform to select some data based on where conditions checking Response 1, Response 2 &; Response 3 parameters but it gives me Error

  while select * from appLog
            where appLog.ReceiptNo == ""  && appLog.Response1 != "" && appLog.Response2 != "" && appLog.Response3 == ""
        {
                resultSet.addEnd(appLog.Response2);
       
        }


Container and unbounded string fields are not allowed in a WHERE expression.

Note: After finding error details I came to know you can not use MEMO fields in where clause and have to use IF condition .

Therefore the query was changed as below.

  while select * from appLog
            where appLog.ReceiptNo == ""
        {
            response1 = appLog.Response1;
            response2 = appLog.Response2;
            response3 = appLog.Response3;
         
            if(response1 != "" && response2 != "" && response3 == "")
            {
                resultSet.addEnd(appLog.Response2);
            }
        }


Thursday, August 4, 2016

Executing SQL Query in Dynamics AX

X++ language supports a number of ways to execute native SQL against any SQL data source.

Note: don't forget to set RunOn Property to Server of the class. Job:

static void BillingQuery(Args _args)
{
    RunSqlQuery q = new RunSqlQuery();
    q.RunSqlQueryMethod();

}

Class:

class RunSqlQuery
{
}

public void RunSqlQueryMethod()
{
     str sql;
    Connection conn;
    SqlStatementExecutePermission permission;
    Statement Stmt;
    ResultSet R;
    str result;
    ;
    sql = "select ACCOUNTNUM from custTable";

    conn = new Connection();
    permission = new SqlStatementExecutePermission(sql);
    permission.assert();

    Stmt = conn.createStatement();
    R = Stmt.executeQuery(sql);
    while ( R.next() )
    {
        result =  R.getString(1);
    }

    // the permissions needs to be reverted back to original condition.
    CodeAccessPermission::revertAssert();
}

Below the useful links.

http://blog.rahulsharma.in/2010/04/dynamics-ax-sqlstatementexecutepermissi.html

https://msdax.wordpress.com/2010/06/21/executing-sql-directly-from-x/