我正在尝试创建简单的需求管理数据库。基本上我有2张桌子,如下所示:

具有2列的Contract_requirements:

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

我想编写查询来接收这样的表:
CR_ReqID  |Description                  |where used?
reqCR1    |Contract req description 1   |reqSW1, reqSW2
reqCR2    |Contract req description 2   |reqSW1, reqSW3

表“合同要求”和“软件要求”通过“RootReq”列关联

香港专业教育学院试图实现艾伦·布朗的代码
http://allenbrowne.com/func-concat.html#Top

这是我的查询
SELECT Contract_requirements.CR_ReqID, ConcatRelated("SW_ReqID     ","SW_requirements","RootReq = """ & [CR_ReqID] & """") AS Expr1
FROM Contract_requirements;

但我在Access中遇到错误

“错误3831:不能在WHERE或HAVING子句中使用多值字段'RootReq'”

你们能帮我使这个工作吗?
提前致谢

最佳答案

建立一个查询,将多值字段元素扩展到单个记录。

查询1

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

然后将该查询用作ConcatRelated()函数的源。
SELECT Contract_Requirements.*,
ConcatRelated("SW_ReqID","Query1","[SW_Requirements.RootReq.Value]='" & [CR_ReqID] & "'") AS WhereUsed
FROM Contract_Requirements;

建议不要在命名约定中使用空格或标点符号/特殊字符。

关于sql - 将其中具有多个值的多行连接到MS Access中的单行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56764071/

10-12 18:40