简体   繁体   English

在Access 2007中构建查询?

[英]Building queries in Access 2007?

I'm trying to build a query where I'm able to get names of clients. 我正在尝试建立一个查询,以获取客户名称。 So I have two tables, the 1st table has a column AppointmentNO , and this field is a number (there are other columns but they're irrelevant). 因此,我有两个表,第一个表具有一列AppointmentNO ,而该字段是一个数字(还有其他列,但它们是不相关的)。 In the 2nd table I have an ID as primary key, FirstName , LastName . 在第二张表中,我有一个ID作为主键, FirstNameLastName ID is what matches the AppointmentNO in the first table. ID与第一个表中的AppointmentNO匹配。

Basically what I'm trying to do is link the two tables so that when I have an AppointmentNO in one column, I can see the LASTNAME associated with it in the 2nd column (need to include this in my report). 基本上,我想做的是链接两个表,以便当我在一个列中有一个AppointmentNO时,我可以在第二列中看到与它关联的LASTNAME (需要在我的报告中包括它)。 I'm trying to link the AppointmentNO to ID and on JOIN PROPERTIES -> include all records from left table (1st table) and only those from right table (2nd table) where the joined fields are equal. 我正在尝试将AppointmentNO链接到ID并在JOIN PROPERTIES上->包括来自左表(第一张表)的所有记录,并且仅包括来自右表(第二张表)的所有记录(连接字段相等)。

If I try to run the query it gives me a MISMATCH error. 如果我尝试运行查询,则会出现MISMATCH错误。 What am I doing wrong? 我究竟做错了什么?

The type mismatch error could be happening: 类型不匹配错误可能正在发生:

  1. because the two fields that you're trying to join aren't set as the same data type (eg one is Number and the other is Text) - check this in the Properties tabs for the relevant fields in each table; 因为您要连接的两个字段未设置为相同的数据类型(例如,一个是Number,另一个是Text),请在“属性”标签中选中此属性,以获取每个表中的相关字段;

  2. it could be that Access has a join between the tables involving other fields (it will sometimes do this with AutoIDs) - you can check the relationships (and establish them) in the Tools -> Relationships window (where this is located might depend on your version). 可能是Access在涉及其他字段的表之间具有联接(有时会使用AutoID做到这一点)-您可以在“工具”->“关系”窗口中检查关系(并建立关系)(此位置可能取决于您版)。 You can also use this tool to explicitly build the relationship, by connecting your 'ID' to 'AppointNO' - though you should still ensure that the fields are of the same data type. 通过将“ ID”连接到“ AppointNO”,您还可以使用此工具显式建立关系-尽管您仍应确保字段具有相同的数据类型。

ADDITION: Based on what you're describing, I think this is the situation (correct me if I'm wrong, though): 另外:根据您的描述,我认为这是情况(不过,如果我错了,请纠正我):

Three tables - Client, AppointmentNO, Children 三张桌子-客户,约会编号,孩子

In each table, there is a 'MemberID' - this is primary key in Client Table, and is Foreign Key in the other tables. 在每个表中都有一个“ MemberID”-这是客户端表中的主键,而在其他表中是外键。

The Children and AppointmentNO tables are linked to Client table by one-to-many relationships (a client can have >1 children and >1 appointment). Children和AppointmentNO表通过一对多关系链接到Client表(一个客户可以有1个以上的孩子和1个以上的约会)。

I'd set this up so that the Member ID is the same datatype in each table, and join all tables on that field. 我将其设置为使Member ID在每个表中都是相同的数据类型,并在该字段上联接所有表。 Then, when set up a query that gives you MemberID, ClientName, ClientDOB (and anything else you want from the client table), ChildName, and AppointmentID. 然后,在设置一个查询时,该查询将为您提供MemberID,ClientName,ClientDOB(以及从客户端表中获取的其他任何内容),ChildName和AppointmentID。 Once the query is working and giving you the desired output, you can build a report and group the output by Client and Client Description, so you'll get "Client A" followed by list of appointments and children, then "Client B" etc. 查询正常工作并提供所需的输出后,您可以构建报告并按“客户和客户描述”对输出进行分组,这样您将获得“客户A”,然后是约会和子项列表,然后是“客户B”等。

Hope that's clear-ish. 希望那是清晰的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM