Query to populate parentitem lookupcode

Jun 09, 2010 2 Replies

Hello guys, How to display parentitem lookupcode instead of id. For example : If i write : select itemlookupcode,description,parentitem from item where parentitem0



it will show :


100111,Marlboro Lights,5676

Instead of id i want it to show its parent item lookupcode..how do i do that?



How do i join inside something that exists in one table


Hi Fez

I use a view to "cross join" and be able to see the item lookup code of an item's parent. I suck at cross joins - learn them once, then forget them. So views many times save my bacon. This view sets up a list of items that are parents.

CREATE VIEW ViewParent AS

SELECT ID as ParentID, ItemLookupCode as ParentILC, Description as ParentDescription, Quantity as ParentQuantity FROM Item where ID in (select ParentItem from Item where ParentItem

Now you can join the item table to the view...

select i.itemlookupcode, i.description, vp.parentilc as ParentLookupCode from item i left join viewparent vp on i.parentitem = vp.ParentID where i.parentitem > 0

This is some old code I found on my machine - I think its still good but I have the tendency to goof around with old queries, hopefully I didn't save anything funky on it. Try it and let me know if it works.

H> Hello guys,

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required