Skip to content
Advertisement

Concatenating multiple rows, with multiple values in it, into single line in MS Access

I am trying to create simple requirements management database. Basically I have 2 tables like below:

Contract_requirements with 2 columns:

CR_ReqID    |   Description
reqCR1      |   Contract req description 1
reqCR2      |   Contract req description 2

SW_requirements

Title               |   SW_ReqID     |  RootReq
SW req description 1|   reqSW1       |   reqCR1, reqCR2
SW req description 2|   reqSW2       |   reqCR1
SW req description 3|   reqSW3       |   reqCR2

And I would like to write query to receive such a table:

CR_ReqID  |Description                  |where used?
reqCR1    |Contract req description 1   |reqSW1, reqSW2  
reqCR2    |Contract req description 2   |reqSW1, reqSW3

Tables “Contract requirements” and “SW requirements” are in relation via column “RootReq”

Ive tried to implement code from Allen Browne http://allenbrowne.com/func-concat.html#Top

This is my query

SELECT Contract_requirements.CR_ReqID, ConcatRelated("SW_ReqID     ","SW_requirements","RootReq = """ & [CR_ReqID] & """") AS Expr1
FROM Contract_requirements;

but I get error in Access

“Error3831: The multi-valued field ‘RootReq’ cannot be used in a WHERE or HAVING clause”

Could you guys help me to make this working? Thanks in advance

Advertisement

Answer

Build a query that expands the multi-value field elements to individual records.

Query1

SELECT SW_Requirements.Title, SW_Requirements.SW_ReqID, SW_Requirements.RootReq.Value 
FROM SW_Requirements;

Then use that query as source for ConcatRelated() function.

SELECT Contract_Requirements.*, 
ConcatRelated("SW_ReqID","Query1","[SW_Requirements.RootReq.Value]='" & [CR_ReqID] & "'") AS WhereUsed
FROM Contract_Requirements;

Advise not to use spaces nor punctuation/special characters in naming convention.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement