2013-01-24

Translating enumerations to T-SQL strings


If you are anything like me, you are spending a lot of time designing querys to transfer data from your ERP system to a data warehouse, in Dynamics AX a lot of the data is represented by enumerations, now that kind of data does not look very nice and user friendly in a data warehouse, to translate them in your T-SQL query I use this simple script to get the labels for each enumeration index. Simply replace the “PriceType” string with any enum in the system.

static void GAB_PrintEnumValues(Args _args)
{
    DictEnum DEnum;
    int      i;
    ;


    DEnum = new DictEnum(enumName2Id("PriceType"));
    for (i=0; i < DEnum.values(); i++)
    {
        info("when PostingType  = " + int2str(DEnum.index2Value  (i)) + "

        then  \'" + DEnum.index2Label(i) + "\'");
    }
}


The outcome should look like this, simply right click and paste this into your query window.

Inga kommentarer:

Skicka en kommentar