Saturday 26 May 2018

All Select statements in Ax 2012


 Select statements:

1.select  All records
CustTable custTable;
select * from Custtable; (or) select Custtable;
select firstOnly Custtable where custtable.custAccount =="1001";

//select first 10 record.
static InventTable find(ItemId   itemId= "1001",boolean  update = false)
{
    InventTable inventTable;
    ;
    select firstonly10 inventTable
            index hint ItemIdx where inventTable.itemId== itemId;
    }
    return inventTable;
}

//select first 100 record.
static InventTable find(ItemId   itemId= "1001",boolean  update = false)
{
    InventTable inventTable;
    ;
    select firstonly100 inventTable
            index hint ItemIdx where inventTable.itemId== itemId;
    }
    return inventTable;
}

//select first 1000 record.
static InventTable find(ItemId   itemId= "1001",boolean  update = false)
{
    InventTable inventTable;
    ;
    select firstonly1000 inventTable
            index hint ItemIdx where inventTable.itemId== itemId;
    }
    return inventTable;
}
//Reverse and Order by example
select reverse custTable order by AccountNum;

//sum example
CustTable custTable;
;
select sum(Amount) from custTable;

// Group By
CustTable custTable;
;
while select sum(Amount) from custTable
    group by CustGroup
{
    info(strFmt("%1--%2",custTable.CustGroup,custTable.Amount));
}
(or)
select sum(Amount) from custTable
    group by CustGroup where custTable.CustGroup == "30";
{
    info(strFmt("%1--%2",custTable.CustGroup,custTable.Amount));
}

No comments:

Post a Comment