【发布时间】:2015-06-13 04:23:22
【问题描述】:
我目前正在尝试在 Microsoft Dynamics AX2012 中执行 SQL 查询,以使用 DATEPART 函数输出交货日期后的一年。
我在 AOT 中创建了一个类“CustRerportDemo”,并在尝试执行查询时,即仅从表“SalesTable”中的“deliverydate”字段中查询出年份。遇到错误提示:
变量Datepart尚未声明
我知道 datepart 是 SQL 中的函数调用,不需要声明。因此,我想知道为什么以及如何纠正这个问题?我只是想显示从交货日期算起的年份。
因此,如果日期是 2016 年 6 月 13 日,则查询结果将只是 2016 年或 16 年。 我附上了以下代码。请帮忙。
public void processReport()
{
CustTable custTable;
SalesTable salesTable;
//select all customers
while select * from custTable
{
//clear the temporary table
custReportRDPTmp.clear();
//assign customer account and name
custReportRDPTmp.CustAccount = custTable.AccountNum;
custReportRDPTmp.Name = custTable.name();
//select count of invoiced sales order of customer
select count(RecId) from salesTable
where salesTable.CustAccount == custTable.AccountNum
&& salesTable.SalesStatus == SalesStatus::Invoiced;
custReportRDPTmp.SalesOrderInvoiceCount = int642int(salesTable.RecId);
//New Column to display PaymentMode
select PaymMode
from salesTable
where salesTable.PaymMode == custTable.PaymMode;
custReportRDPTmp.Payment = SalesTable.PaymMode;
//New Column to display SalesAmountTotal by drawing from a different table using a JOIN statement
select smmSalesAmountTotal
from salesTable;
custReportRDPTmp.SalesAmt = salesTable.smmSalesAmountTotal;
//New Column to display month from delivery date
select DATEPART("yyyy", DeliveryDate) as year
// To extract a single value for year and month from DeliveryDate in SalesTable
from salesTable
/* where payment in (select count(payment) from salesTable
where salesTable.CustAccount == custTable.AccountNum
&&*/
//insert in temporary table buffer
custReportRDPTmp.insert();
}
}
编辑代码:
select firstOnly DeliveryDate
from salesTable
where salesTable.CustAccount == custTable.AccountNum;
//Get Year from date
custReportRDPTmp.DateTimeStamp = year(salesTable.DeliveryDate);
结果如图:
【问题讨论】:
标签: sql axapta x++ dynamics-ax-2012 datepart