Monday, February 17, 2014

Using sub-query through X++

static void SelectAsExpression3Job(Args _args)
{
    int64 nRecId,
        nCount;
    str sAccountNum,
        sName;
    ;
    // Test_1.a
    sAccountNum = (select firstonly AccountNum from CustTable
        order by AccountNum desc
        where 0 == 0 // 'where' must occur after 'order by'.
        ).AccountNum;
    info(strFmt("Test_1.a: %1", sAccountNum));

    // Test_1.b
    sAccountNum = (select maxof(AccountNum) from CustTable).AccountNum;
    Global::info(strFmt("Test_1.b: %1", sAccountNum));

    // Test_2.c
    nRecId = (select maxof(RecId) from CustTable
        where CustTable.Blocked == CustVendorBlocked::No).RecId;
    info(strFmt("Test_2.c: %1", nRecId));

    // Test_2.d
    nRecId = (select count(RecId) from CustTable
        where CustTable.Blocked == CustVendorBlocked::No).RecId;
    info(strFmt("Test_2.d: %1", nRecId));

    // Test_3
    sName = (select Name from AssetTable
        where AssetTable.AssetId ==
            (select AssetId from AssetTrans
                where AssetTrans.AssetId == 'VEHC-005' //"CNC-01"
            ).AssetId).Name;
    info(strFmt("Test_3: %1", sName));
}

No comments:

Post a Comment