代码之家  ›  专栏  ›  技术社区  ›  user3553260

带简单示例的dlookup字符串标准

  •  1
  • user3553260  · 技术社区  · 6 年前

    tblauthors公司

    ID  FirstName   LastName
    1   Rob         Cooper
    2   Geoff       Griffith
    3   Teresa      Hennig
    4   Jerry       Dennison
    

    ID  Author
    1   Rob
    2   Rob
    3   Rob
    4   Geoff
    5   Geoff
    6   Teresa
    7   Jerry
    

    当选择打开tblChapters表时,我单击创建查询按钮。

    我的dlookup使用字符串。

    RetrieveLastName: DLookUp("[LastName]","[tblAuthors]","[FirstName]='" & [Author] & "'")
    

    当我举个例子:

    RetrieveLastName: DLookUp("[LastName]","[tblAuthors]","[FirstName]='Teresa'")
    

    但这不是我想要的。

    谢谢!

    我查看了多个网站,尝试了数字语法。

    1 回复  |  直到 6 年前
        1
  •  1
  •   ccarpenter32    6 年前

    如果我正确理解了你的问题,你在寻找如下数据(从表中 tblChapters

    +----+--------+----------+
    | id | Author | LastName |
    +----+--------+----------+
    |  1 | Rob    | Cooper   |
    |  2 | Rob    | Cooper   |
    |  3 | Rob    | Cooper   |
    |  4 | Geoff  | Griffith |
    |  5 | Geoff  | Griffith |
    |  6 | Teresa | Hennig   |
    |  7 | Jerry  | Dennison |
    +----+--------+----------+
    

    我建议您使用以下SQL:

    SELECT tc.id, tc.Author, ta.LastName 
    FROM tblChapters tc
    INNER JOIN tblAuthors ta ON tc.Author = ta.FirstName
    ORDER BY tc.ID
    

    使用 Design View

    TBL章 tblAuthors ,链接打开 tblChapters.Atuhor tblAuthors.FirstName

    +--------+-------------+-------------+------------+
    | Field: |     id      |   Author    |  Lastname  |
    +--------+-------------+-------------+------------+
    | Table: | tblChapters | tblChapters | tblAuthors |
    +--------+-------------+-------------+------------+
    

    以下内容: