query in standard Axapta is really limited because I can’t define distinct. Here is the code to define it, but as a note, you need to define it as a server run object.
public client server static void GetBatchListed( itemId _ItemId)
{
Connection conn;
Statement stmt;
ResultSet R;
SqlStatementExecutePermission perm;
str sql;
TSWrkInventBatch TSWrkInventBatch;
;
conn = new connection();
stmt = conn.createStatement();
sql = “select * from InventBatch IB inner join (“;
sql += “select distinct c.InventBatchId from Inventsum a inner join InventDim b “;
sql += “on a.Inventdimid = b.inventdimid “;
sql += “inner join InventBatch c on b.InventBatchId = c.InventBatchId “;
sql += “where a.ItemId = %1 and “;
sql += “c.inventBatchId <> ”) as TBJoin on IB.InventBatchId = TBJoin.InventBatchId”;
perm = new SqlStatementExecutePermission(strfmt(sql,_ItemId));
perm.assert();
R = Stmt.executeQuery(sql);
while (R.next())
{
info( R.getString(fieldnum(InventBatch, InventBatchId)));
}
}

February 20, 2009 at 7:52 pm |
Where would you place this code? I tried to build this as a class, but the editor throws a syntax error on the first line.
February 21, 2009 at 12:43 pm |
what error did you get?
I put this code as a new class