我如何合并多行(相关的)信息,而在我的报告中没有重复的值?

问题描述 投票:0回答:2

我已经创建了具有以下表的数据库:

学生列表学生手册编号学生需求教师信息

在“学生需求表”中,我输入的信息与此类似:

学生证栏,姓,名,阅读特殊需要

123456鼠标米奇字典123456鼠标Mickey额外时间123456老鼠米奇小团体123456鼠标米奇类型答案选择654321 Ducky Daffy字典654321鸭Daffy词库654321 Daffy Ducky小团体

我需要像这样将它拉出:

学生ID列,姓,名,阅读特殊需要

123456鼠标米奇字典,额外时间,小组讨论,输入答案选项654321 Duck Daffy字典,词库,小团体

我在报表控制源中使用了concatrelated函数,它可以将所有需求放在一起,但是由于我的查询多次列出了该学生,因此它在报表上多次列出了该学生。像这样:

学生证栏,姓,名,阅读特殊需要

123456鼠标米奇字典,额外时间,小组讨论,输入答案选项123456鼠标米奇字典,额外的时间,小组,键入答案选择123456鼠标米奇字典,额外的时间,小组,键入答案选择123456鼠标米奇字典,额外的时间,小组,键入答案选择654321 Ducky Daffy字典,同义词库,小词典654321 Ducky Daffy字典,同义词库,小词典654321 Duck Daffy字典,同义词库,小词典

我已经尽力想解决这个问题-导出报告并删除重复项-但随后导出被截断为255个字符-因此不起作用。当然,我缺少一些相对容易的东西-但我无法弄清楚!

ms-access concatenation rows crosstab ms-access-2016
2个回答
0
投票

使用我的DJoin function和类似的查询:

SELECT 
    [Student Needs].[Student ID], 
    [Student Needs].[Last Name], 
    [Student Needs].[First Name], 
    DJoin("[Reading Special Need]","[Student Needs]","[Student ID] = " & [Student ID] & "",", ") AS [Reading Special Needs]
FROM 
    [Student Needs]
GROUP BY 
    [Student Needs].[Student ID], 
    [Student Needs].[Last Name], 
    [Student Needs].[First Name];

输出:

enter image description here


0
投票

我创建了一个名为“从表字段获取列表”的模块,并且其中包含以下代码:

Public Function GetList(sTable As String, sField As String, Optional sWhere As String, Optional sDelimiter As String, Optional UniqueValues As Boolean) As String
'   compiles all the data from a single field in a table and returns them in a string.
'   has options for providing a sql crieria, a delimiter, and if unique values should be returned
    Dim rs As Recordset
    Dim sList As String
    Dim sChar As String

    If sDelimiter = "" Then
        sChar = ","
    Else
        sChar = sDelimiter
    End If
    Set rs = CurrentDb.OpenRecordset("Select " & IIf(UniqueValues, "Distinct ", "") & sField & " From " & sTable & IIf(sWhere <> "", " Where " & sWhere, ""))
    Do While Not rs.EOF
        sList = sList & sChar & rs.Fields(sField)
        rs.MoveNext
    Loop
    rs.Close
    Set rs = Nothing

    sList = Mid(sList, 2) & sChar
    GetList = sList

End Function

在您选择的查询中,您可以尝试:

SELECT [Student ID], [Last Name], [First Name], 
GetList("[Student Needs]","[Reading Special Need]","[Student ID] = " & [Student ID]) AS [Reading Special Needs]
FROM [Student Needs]
GROUP BY [Student ID], [Last Name], [First Name];

我还建议您在所有表和字段名称上使用下划线或CamelCase而不是空格。这样,您可以避免在语句中使用方括号。这是一种更好的编程习惯。例如:

下划线 SELECT Student_ID, Last_Name, First_Name FROM Student_Needs

CamelCase SELECT StudentID, LastName, FirstName FROM StudentNeeds

© www.soinside.com 2019 - 2024. All rights reserved.