Microsoft Dynamics 中的日期部分函数错误 SQL
Datepart function error in Microsoft Dynamics SQL
我目前正在尝试在 Microsoft Dynamics AX2012 中执行 SQL 查询,以使用 DATEPART 函数输出从交货日期算起的年份。
我在 AOT 中创建了一个 class "CustRerportDemo",并在尝试执行查询时,即仅从 "deliverydate" 字段中查询出年份 table "SalesTable"。遇到错误提示:
Variable Datepart has not been declared
我知道 datepart 是 SQL 中的函数调用,不需要声明。因此,我想知道为什么以及如何纠正这个问题?我只是想显示从交货日期算起的年份。
因此,如果日期是13/06/2016,那么查询出来的结果就是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);
结果如图:
X++ select 语句是 not SQL 因此你不应该假设任何或所有 SQL 函数在 X++ 中可用;他们不是!
有个日期函数,你搜索的那个叫做year。
它不属于 select 不过:
select firstonly DeliveryDate from salesTable;
y = year(salesTable.DeliveryDate);
我目前正在尝试在 Microsoft Dynamics AX2012 中执行 SQL 查询,以使用 DATEPART 函数输出从交货日期算起的年份。
我在 AOT 中创建了一个 class "CustRerportDemo",并在尝试执行查询时,即仅从 "deliverydate" 字段中查询出年份 table "SalesTable"。遇到错误提示:
Variable Datepart has not been declared
我知道 datepart 是 SQL 中的函数调用,不需要声明。因此,我想知道为什么以及如何纠正这个问题?我只是想显示从交货日期算起的年份。
因此,如果日期是13/06/2016,那么查询出来的结果就是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);
结果如图:
X++ select 语句是 not SQL 因此你不应该假设任何或所有 SQL 函数在 X++ 中可用;他们不是!
有个日期函数,你搜索的那个叫做year。
它不属于 select 不过:
select firstonly DeliveryDate from salesTable;
y = year(salesTable.DeliveryDate);