How to concatenate multiple rows in Access involving a Link?

前端 未结 2 795
梦毁少年i
梦毁少年i 2021-01-28 23:16

I have the following problem concerning my Access Database:

I have 3 tables which are tblComponents, tblErrors, and linkComponentsErrors. This is a many to many relations

相关标签:
2条回答
  • 2021-01-28 23:51

    If you don't want to use DJoin, you can do two queries and use the ConcatRelated function by Allen Browne:

    A helping query "Hilfsabfrage" that does the join with the link:

    SELECT tblErrors.errName, tblErrors.errID, linkComponentsErrors.CompID FROM tblErrors INNER JOIN linkComponentsErrors ON tblErrors.errID = linkComponentsErrors.errID
    

    And the main query:

    SELECT tblComponents.compName, ConcatRelated("errName", "Hilfsabfrage", "compID = " & [compID]) FROM tblComponents
    

    Don't do this in your main query: SELECT tblComponents.compName, ConcatRelated("errName", "Hilfsabfrage", "compID = " &[Hilfsabfrage].[compID]) FROM tblComponents . The query has do be without the [Hilfsabfrage].

    You can also put more than one ConcatRelated in your query.

    0 讨论(0)
  • 2021-01-29 00:03

    You can use my DJoin function for this:

    SELECT 
        tblComponents.compname, 
        DJoin(
            "errname",
            "SELECT compID, errname 
                FROM linkComponentsErrors 
                INNER JOIN tblErrors ON linkComponentsErrors.errID = tblErrors.errID",
            "compID = " & [tblComponents].[compID] & "",
            ", ") AS errnames
    FROM 
        tblComponents 
    INNER JOIN 
        linkComponentsErrors ON tblComponents.compID = linkComponentsErrors.compID
    GROUP BY 
        tblComponents.compname, 
        DJoin(
            "errname",
            "SELECT compID, errname 
                FROM linkComponentsErrors 
                INNER JOIN tblErrors ON linkComponentsErrors.errID = tblErrors.errID",
            "compID = " & [tblComponents].[compID] & "",
            ", "), 
        tblComponents.compID
    ORDER BY 
        tblComponents.compID;
    

    Output:

    0 讨论(0)
提交回复
热议问题