使用ConcatRelated()与2 Where Criteria

时间:2017-11-04 01:21:35

标签: sql ms-access concatenation ms-access-2013

我在查询中运行它 - 它在我实际运行查询时抛出错误

  

错误3061 - 参数太少。预计1

这是我的语法:

SELECT [ExcelImport].[unitID], [ExcelImport].Department, 
ConcatRelated('[OrderID]','[ExcelImport]','[unitID] = ' & [unitID] & ' AND [Department] = ''' & [Department]) AS [SID]
GROUP BY [ExcelImport].[unitID], [ExcelImport].[Department]
ORDER BY [ExcelImport].[unitID];

这是使用Allen Browne的ConcatRelated()函数

http://allenbrowne.com/func-concat.html

1 个答案:

答案 0 :(得分:2)

当用作特殊字符时,引号和撇号必须始终成对。如果您发现很难确定配对是否正确,请使用引号来定义参数参数和文本分隔符的撇号。在[部门]之后需要一个关闭的撇号分隔符:

SELECT [ExcelImport].[unitID], [ExcelImport].Department, 
ConcatRelated("[OrderID]","[ExcelImport]","[unitID] = " & [unitID] & " AND [Department] = '" & [Department] & "'") AS [SID]
GROUP BY [ExcelImport].[unitID], [ExcelImport].[Department]
ORDER BY [ExcelImport].[unitID];