web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

SQL query to get the related products of an item

(1) ShareShare
ReportReport
Posted on by 335

HI, Below is the sql query to get the related products of an item.

it can be helpful for many because sharing is caring.

-------------------------------------- sql query to get the related products of an item -------------------------------------

Select Inv.ITEMID, ET.NAME ,cat.NAME as Category,RlT.NAME as 'Relation Type'
,(select Itemid from inventtable where inventtable.PRODUCT = pp.RECID and inventtable.DATAAREAID='ABC' ) as 'Related Product'
from INVENTTABLE inv
inner join ECORESPRODUCTTRANSLATION as ET on Inv.PRODUCT = ET.PRODUCT AND ET.LANGUAGEID = 'en-us'
left outer join ECORESPRODUCT p on p.RECID = inv.PRODUCT
left outer join ECORESPRODUCTCATEGORY PC on pc.PRODUCT = p.RECID
left outer join ECORESCATEGORY cat on cat.RECID = pc.CATEGORY
inner join ECORESPRODUCTRELATIONTABLE as RT on RT.PRODUCT1 = p.RECID
inner join ECORESPRODUCT pp on pp.RECID = RT.PRODUCT2
inner join ECORESPRODUCTRELATIONTYPE RlT on RlT.RECID = RT.PRODUCTRELATIONTYPE
--inner join INVENTTABLE PPINV on PPINV.PRODUCT = pp.RECID
where inv.DATAAREAID='ABC'
ORDER BY Inv.ITEMID DESC

---------------------------------------------------------------------------------------------------------------------------------------------

Rgards

zeeshan adeel

I have the same question (0)
  • Martin Dráb Profile Picture
    237,884 Most Valuable Professional on at

    Hi Zeeshan, thank you for sharing your knowledge, but note that discussion forums are intended for discussion. A better place for this kind of posts would be a blog. You can have one even here at the Dynamics Community site - look at Info Center > Request a New Blog.

    Also, when posting code in the forum, please use Insert > Insert Code (in the rich formatting view). For example:

    select
    	inv.ITEMID,
    	ET.NAME,
    	cat.NAME as Category,
    	RlT.NAME as 'Relation Type',
    	(select ItemId from InventTable where InventTable.PRODUCT = pp.RECID and InventTable.DATAAREAID = 'ABC' ) as 'Related Product'
    from INVENTTABLE inv
    inner join ECORESPRODUCTTRANSLATION as ET on inv.PRODUCT = ET.PRODUCT AND ET.LANGUAGEID = 'en-us'
    left outer join ECORESPRODUCT p on p.RECID = inv.PRODUCT
    left outer join ECORESPRODUCTCATEGORY PC on pc.PRODUCT = p.RECID
    left outer join ECORESCATEGORY cat on cat.RECID = pc.CATEGORY
    inner join ECORESPRODUCTRELATIONTABLE as RT on RT.PRODUCT1 = p.RECID
    inner join ECORESPRODUCT pp on pp.RECID = RT.PRODUCT2
    inner join ECORESPRODUCTRELATIONTYPE RlT on RlT.RECID = RT.PRODUCTRELATIONTYPE
    where inv.DATAAREAID = 'ABC'
    ORDER BY inv.ITEMID DESC

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans