Ms access MS Access将记录移动到字段中
我有一个ODBC连接到一个我不拥有也无法更改的数据库。我希望做的是将相关记录合并到一个记录中。这种关系是一对多的关系 我有一个学生管理系统,想导出一个呼叫列表,该列表提供自动呼叫服务(按呼叫收费)。如果有多个学生住在一所房子里,我想只给它打一次电话 所需的调出文件结构:Ms access MS Access将记录移动到字段中,ms-access,field,record,denormalization,Ms Access,Field,Record,Denormalization,我有一个ODBC连接到一个我不拥有也无法更改的数据库。我希望做的是将相关记录合并到一个记录中。这种关系是一对多的关系 我有一个学生管理系统,想导出一个呼叫列表,该列表提供自动呼叫服务(按呼叫收费)。如果有多个学生住在一所房子里,我想只给它打一次电话 所需的调出文件结构: PHONE Inst1 Inst2 Inst3 555-5555 John was absent today Jane was absent tod
PHONE Inst1 Inst2 Inst3
555-5555 John was absent today Jane was absent today Joe was absent today
根据现有数据:
PHONE Inst
555-5555 John was absent today
555-5555 Jane was absent today
555-5555 Joe was absent today
有什么建议吗?我的第一个倾向是使用交叉表查询;然而,这可能会有点毛茸茸的 在一个模块中剪切一些VBA代码,将它们连接在一起,然后插入到另一个表中(类似于下面的内容-完全未经测试,可能在某个地方损坏),怎么样
你使用的是什么编程语言?另一个类似的问题是:尽管公认的解决方案要求你选择一行中包含多少学生的上限。考虑到它的访问权限,我认为我们可以放心地假设他使用的是VBA。我同意这不是最有效的方法,但是,如果您只是为报告生成数据,它将以最小的麻烦完成工作。这就是我的做法。
dim strAbsent as string
dim currPhone as string
dim lastPhone as string
Dim db As Database
Dim rstAbsent As Recordset
Dim rstAbsentReport As Recordset
Set db = CurrentDb
Set rstAbsent = dbV.OpenRecordset("select * from Absent", _
dbOpenDynaset, dbSeeChanges)
Set rstAbsentReport = dbV.OpenRecordset("select * from AbsentReport", _
dbOpenDynaset, dbSeeChanges)
'...
do while not rstAbsentReport.EOF
currPhone = rstAbsentReport("phone")
lastPhone = currPhone
do while currPhone = lastPhone _
and not rstAbsentReport.EOF
strAbsent = strAbsent & ";" & rstAbsentReport ("comment")
'Yes I know concatenating strings this way is terribly inefficient
rstAbsentReport.MoveNext
if not rstAbsentReport.EOF then
currPhone = rstAbsentReport("phone")
end if
last
rstAbsent.AddNew
rstAbsent ("call") = strAbsent
rstAbsent.Update
loop
'... clean up of recordset variables left as an exercise