x++


Regarding X++ query


How i convert below SQL query into X++ code.I uses a empltable and join this table with HRPPARTYPOSITIONTABLERELAT2226,and in HRPPARTYPOSITIONTABLERELAT2226
used self join..
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'
From the table names it seems you are on version AX 2009 or earlier. And the requirement behind your SQL query seems to be to show some employee data along with some additional data from the last position they held.
Unfortunately as far as I know there is no way like in SQL to do this in one query. You need at least two. One way to do it is to first determine all the last positions held by employees by doing an aggregated query on the HRPPartyPositionTableRelationship table. From these results you can then select the corresponding EmplTable and full HRPPartyPositionTableRelationship records.
This could look like the following code. Note that this is not an exact representation of your query, but I'm sure you can add the missing field lists and criteria on your own.
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));
}

Related Links

Refresh the main screen in ax dynamics 2009
How to insert into a table field with value from a display method dependent of string
x++ cannot read registry entry
How do I get the caller Form's name in the Insert() of a table in AX 2012?
How to lookup into another table using EDT AX 2012
Set a Date Value to a Date Field in AX2012
Determine if a job is running in X++ code
Dynamics AX 2012 parsing Int32 to table field integer
Cancel Sales order packing slip through x++
Transferring open account records between customers
How to make sure that a form is only opened once?
Extend system menu in Dynamics AX 2012?
How to show selected items of certain table on the different table in Dynamics AX 2012?
AllowEdit doesn't work properly in Dynamics AX
AX 2012 how to set args record datasource in X++
Clients seem to be running old (buggy) code after XPO project import

Categories

HOME
gridview
forms
ns-3
shiro
computer-science
accessibility
fhir
plist
mod-security
mautic
gource
plink
magnetic-cards
symbol
intershop
red5
easyphp
identity-management
bourbon
php-mysqlidb
flask-sqlalchemy
perlbrew
windows-server-2003
entity-relationship-model
underscore.js
handler
rpgle
gp
sqlpackage
testcomplete
custom-controls
utorrent
weather
git-squash
rselenium
spring-security4
clickjacking
linkedhashmap
apic
node-mssql
ods
odoo-website
drupal-theming
uiimage
snapchat
gitlist
wcftestclient
spring-integration-sftp
yii2-api
datamaps
stdmap
qtranslate
cup
bbpress
janus
lsyncd
flyout
flac
filenet
pocketsphinx-android
omxplayer
actor-platform
watch-os-2
macaulay2
mta
tooleap
jclouds
freepbx
nservicebus5
stream-processing
query-by-example
thread-sleep
false-sharing
jbase
cgi-bin
uncompress
branch-and-bound
node-serialport
zend-currency
qtwebengine
theos
sonarqube-5.0
paw
mutual-authentication
menubar
scriptaculous
cocoalibspotify-2.0
inappsettingskit
tlf
jquery-1.9
joomla3.1
floating-point-exceptions
mysql-error-1205
event-receiver
svk
metaweblog
squishit
ie-compatibility-mode
drupal-fivestar
interprocess
feasibility
sifr3
product-management
netbeans6.1

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App