Query with ConcatRelated (1 Viewer)

Nip351

New member
Local time
Today, 17:39
Joined
May 31, 2017
Messages
8
Ok, this is deep...

I have a working query using ConcatRelated, which is working great with one small piece I want corrected.

This is a database I made for my nephews that play Pokemon. It allows them to enter all aspects to track, see what they need, candies, CP, etc. There are about a dozen and a half reports, such as this one, which lists all Pokemon "Starters" which then lists all other Pokemon that are evolved from that first starter. In this, Starters refers to the initial Pokemon which may evolve into others.

Now in the DB, the PK is the Pokemon ID and each Pokemon has a family ID and SubFamilyID. The Family ID keeps all related Pokemon Together, such as a family would be together (Mom, Dad and all children, grandchildren, etc.). The SubFamilyID keeps tabs on each sequential evolve (such as Mom1,kid2, kid3, kid4 - they are sequential in the same FamilyID.)

So, a piece of the DB would look like this.
(tblmain.jpg)

Not all can evolve, some evolve once or more.

The issue is that when using the Concatrelated in this query I am limiting only showing subfamily of 1, and then concatrelated all related members - the problem is it shows the 1 again in the concatrelated list as shown below.
(Spawns.JPG)
Basically, in the Spawns column, it should not list the Pokemons name (or ID) for the Pokemon under the column Starter.

This is the query I am using:
Code:
SELECT tblmain.Idnum, tblmain.PName AS Starter, 
ConcatRelated("""#"" &format([idnum],""000" & " "") & Pname","[tblmain]","familyid=" & [FamilyID]) AS Spawns, tblmain.SubFamilyID
FROM tblmain
WHERE (((tblmain.SubFamilyID)=1));

I suspect I need a subquery to capture only subfamilyid of 1, then in the concatrelated only include where it is not 1...? I just don't know how to show where subfamilyid <> 1 - it was luck and magic to get this working.

I neglected to mention this is in Access 2002.
 

Attachments

  • images.zip
    141.4 KB · Views: 135
Last edited:

Nip351

New member
Local time
Today, 17:39
Joined
May 31, 2017
Messages
8
I just figured it out! Since WHERE is already part of the ConcatRelated, I just needed to append & " AND SUBFAMILYID <>1" to the end of the ConcatRelated field. It now omits the SubfamilyID of 1 from the Spawns field as requested.
Complete Updated Query:
Code:
SELECT tblmain.Idnum, tblmain.PName AS Starter, ConcatRelated("Pname","[tblmain]","familyid=" & [FamilyID] & "  AND SUBFAMILYID <>1") AS Spawns, tblmain.SubFamilyID
FROM tblmain
WHERE (((tblmain.SubFamilyID)=1));
 
Last edited:

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:39
Joined
Aug 30, 2003
Messages
36,124
Thanks for posting your solution and welcome to the site!
 

Users who are viewing this thread

Top Bottom