Search code examples
viewaxaptax++dynamics-ax-2012-r3computed-field

I want to Split string Using Computed column in views AX2012


I am using Computed columns in views. I have a string stored in one column of a table. I want to split that string using Computed Columns.

eg.

ColumnA =  0001^93.2

Resullt:

ColumnB = 0001
ColumnC = 93.2

Thanks


Solution

  • Use CHARINDEX and SUBSTRING.

    public static server str compColB()
    {
        str result;
    
        result = strFmt("SUBSTRING(%1, 0, CHARINDEX(N'^', %1)"
            , SysComputedColumn::returnField(tableNum(SourceTable), 'viewDataSoure', fieldStr(ViewName, ColumnA))
        );
    
    
        return result;
    }
    
    
    public static server str compColC()
    {
        str result;
    
        result = strFmt("SUBSTRING(%1, CHARINDEX(N'^', %1) + 1, 9999"
            , SysComputedColumn::returnField(tableNum(SourceTable), 'viewDataSoure', fieldStr(ViewName, ColumnA))
        );
    
    
        return result;
    }