如何将下面的SQL查询转换为X++代码。I使用empltable并将此表与HRPPARTYPOSITIONTABLERELAT2226连接,在HRPPARTYPOSITIONTABLERELAT2226中使用自连接..
enter code here
select e.EMPLID,
LastDate.TITLE,
e.DIMENSION3_,
LastDate.ORGANIZATIONUNITID,
LastDate.DESCRIPTION,
e.JOINDATE,
e.CITEXITDATE,
LastDate.VALIDTODATETIME
from EMPLTABLE e,
(select *
from HRPPARTYPOSITIONTABLERELAT2226 bc1
where VALIDTODATETIME = (
Select MAX(VALIDTODATETIME)
from HRPPARTYPOSITIONTABLERELAT2226 bc2
where bc2.REFERENCE= bc1.REFERENCE)) LastDate
where e.EMPLID = LastDate.REFERENCE and EMPLSTATUS != 1 and LastDate.DATAAREAID = 'new' 发布于 2016-10-22 22:29:53
从表名看,您似乎使用的是AX2009或更早版本。SQL查询背后的需求似乎是显示一些员工数据以及他们上一次担任的职位的一些附加数据。
不幸的是,据我所知,没有像SQL那样在一个查询中做到这一点。你至少需要两个。一种方法是首先通过在HRPPartyPositionTableRelationship表上执行聚合查询来确定员工最近担任的所有职位。然后,您可以从这些结果中选择相应的EmplTable和完整的HRPPartyPositionTableRelationship记录。
这可能看起来像下面的代码。请注意,这并不是您的查询的确切表示,但我相信您可以自己添加缺少的字段列表和条件。
EmplTable emplTable;
HRPPartyPositionTableRelationship hrpPartyPositionTableRelationship;
HRPPartyPositionTableRelationship hrpPartyPositionTableRelationshipLatest;
;
while select Reference, maxof(ValidToDateTime) from hrpPartyPositionTableRelationshipLatest
group by Reference
where hrpPartyPositionTableRelationshipLatest.HRMReferenceType == HRMVirtualNetworkReferenceType::Employee
{
select emplTable where emplTable.EmplId == hrpPartyPositionTableRelationshipLatest.Reference
join hrpPartyPositionTableRelationship where hrpPartyPositionTableRelationship.HRMReferenceType == HRMVirtualNetworkReferenceType::Employee
&& hrpPartyPositionTableRelationship.Reference == emplTable.EmplId
&& hrpPartyPositionTableRelationship.ValidToDateTime == hrpPartyPositionTableRelationshipLatest.ValidToDateTime;
info(strFmt('%1, %2, %3, %4', emplTable.EmplId, hrpPartyPositionTableRelationship.Title, hrpPartyPositionTableRelationship.Description, hrpPartyPositionTableRelationship.ValidToDateTime));
}https://stackoverflow.com/questions/40129173
复制相似问题