--Vendor default primary address
Select vt.AccountNum, vt.Party, vt.RecId, lpd.RECID, dpl.LOCATION, lpd.ADDRESS from VENDTABLE vt
join DirPartyLocation dpl on dpl.Party = vt.Party
join LogisticsPostalAddress lpd on dpl.LOCATION = lpd.LOCATION
where vt.DataAreaId = 'usrt' and dpl.ISPRIMARY =1 and lpd.VALIDTO = '2154-12-31 23:59:59.000'
--Warehouse default primary address
Select it.InventLocationId, it.INVENTSITEID, it.RecId, lpd.RECID, lpd.ADDRESS
from INVENTLOCATION it
join InventLocationLogisticsLocation illl on illl.INVENTLOCATION = it.RECID
join LogisticsPostalAddress lpd on lpd.LOCATION = illl.LOCATION
where it.DataAreaId = 'usrt' --and dpl.ISPRIMARY =1
and illl.IsPostalAddress =1 and illl.IsPrimary =1 and lpd.VALIDTO = '2154-12-31 23:59:59.000'