This is the Query to get Tax Registration Number by party Name in Ax 2012. Intermediate table for DirPartyTable and taxRegistration is DirPartyLocation and registrationNumber is the field to get value of tax registration Number.
DirPartyTable DirPartyTable;
DirPartyLocation DirPartyLocation;
taxRegistration taxRegistration;
select * from DirPartyTable
where DirPartyTable.Name == "TestName";
select * from DirPartyLocation
where DirPartyLocation.Party == dirPartyTable.RecId;
select registrationNumber
from taxRegistration
where taxRegistration.DirPartyLocation == dirPartyLocation.RecId;
info(strFmt("reg %1",taxRegistration.RegistrationNumber));