X ++计算列

时间:2017-04-04 15:24:36

标签: axapta x++ aot

我尝试在AOT中重新创建SQL视图,我需要添加引用视图的计算列(FISCALCALENDARFLATTENEDVIEW)。在类中,我无法检索此视图的字段。问题是“sGREGORIANDATE =”行我指定了fieldStr(),不能为View做。我把SQL语句只是为了帮助理解我尝试实现的目标。

CREATE VIEW [dbo].[vw_DimFiscalPeriod] AS 
SELECT 
T1.RECID AS LEDGERRECID, 
T1.PARTITION AS PARTITION, 
T1.RECID AS RECID, 
T2.CALENDARID AS CALENDARID, 
T2.CALENDARRECID AS CALENDARRECID, 
T2.GREGORIANDATE AS GREGORIANDATE, 
T2.MONTH AS MONTH, 
T2.PERIODNAME AS PERIODNAME, 
T2.PERIODOFFSET AS PERIODOFFSET, 
T2.PERIODRECID AS PERIODRECID, 
T2.QUARTER AS QUARTER, 
T2.QUARTEROFFSET AS QUARTEROFFSET, 
T2.YEARNAME AS YEARNAME, 
T2.YEAROFFSET AS YEAROFFSET, 
T2.PARTITION AS PARTITION#2, 
(CAST ((((T1.RECID) * (100000)) + (DateDiff(d, {ts '1900-01-01 00:00:00.000'}, T2.GREGORIANDATE))) AS NVARCHAR(50))) AS LEDGERGREGORIANDATEID 
FROM AXDB.dbo.LEDGER T1 
INNER JOIN 
AXDB.dbo.FISCALCALENDARFLATTENEDVIEW T2 
ON T1.FISCALCALENDAR  =  T2.CALENDARRECID
AND T1.PARTITION  =  T2.PARTITION

我创建了类,但是对于我的计算,不支持视图的对象和列列表中的字段。 sRECID没问题,但sGREGORIANDATE定义不行。

public class vw_DimFiscalPeriod extends common
{
private static server str GregoriandDateID()
{
    str sReturn,
    str sRECID,
    str sGREGORIANDATE;
    DictView dictView;

    dictView = new DictView(tableNum(vw_DimFiscalPeriod));
    sRECID = dictView.computedColumnString(tableStr(Ledger), fieldStr(RecId),FieldNameGenerationMode::FieldList,  true);
    sGREGORIANDATE = dictView.computedColumnString(viewstr(FiscalCalendarFlattenedView),  fieldStr(GregorinaDate), FieldNameGenerationMode::FieldList,  true);

    sReturn = "("+RECID+" * 100000) + DateDiff(d, {ts '1900-01-01 00:00:00.000'}, " + sGREGORIANDATE + " )";

     return sReturn;
}
}

1 个答案:

答案 0 :(得分:0)

我认为这应该是有用的,并且对于sGREGORIANDATE来说应该是这样的:

        sGREGORIANDATE = SysComputedColumn::returnField(tableStr(FiscalPeriodDateView), tableStr(FiscalCalendarFlattenedView), fieldStr(FiscalCalendarFlattenedView, GregorianDate)));