Combine values from related rows into a single concatenated string value

前端 未结 1 1978
無奈伤痛
無奈伤痛 2020-11-22 00:11

I\'m trying to aggregate some instructor data (to easily show which courses an instructor taught in a semester), and up until now I\'ve just accepted having multiple rows fo

相关标签:
1条回答
  • 2020-11-22 00:44

    This is easy using Allen Browne's ConcatRelated() function. Copy the function from that web page and paste it into an Access standard code module.

    Then this query will return what you asked for.

    SELECT
        i.N_ID,
        i.F_Name,
        i.L_Name,
        ConcatRelated(
            "Course_ID",
            "tbl_Courses",
            "N_ID = '" & [N_ID] & "'"
            ) AS Course_IDs
    FROM tbl_Instructors AS i;
    

    Consider changing the data type of N_ID from text to numeric in both tables. If you do that, you don't need the single quotes in the third argument to that ConcatRelated() expression.

    "N_ID = " & [N_ID]
    

    And whenever you need N_ID displayed with leading zeros, use a Format() expression.

    Format(N_ID, "000")
    
    0 讨论(0)
提交回复
热议问题