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

  • Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    RE: SQL query to get the related products of an item

    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,013 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans