如何在Acess报告中使用别名

时间:2016-04-20 14:00:59

标签: ms-access report alias

我在Access SQL查询中创建了一个别名,在我运行查询时它显示为有效列,但是当我尝试在报表中使用该字段时,它会恢复为原始名称,值。如何使报告拉入记录堆栈中返回的别名的值?我是否必须通过VBA这样做?

这是我的报告&#39> 记录来源的查询:

SELECT
    ISO_ID.ISOID,
    ISO_Stats.TransactionCount,
    ISO_Stats.TerminalCount,
    ISO_Stats.MonthEnd,
    m2.TerminalCount,
    m2.TransactionCount,
    m2.MonthEnd,
    m3.TerminalCount,
    m3.TransactionCount,
    m3.MonthEnd
FROM
    (((ISO_ID
    INNER JOIN ISO_Stats AS m2
    ON ISO_ID.[ISOID] = m2.[ISOID])
    INNER JOIN ISO_Stats
    ON (ISO_ID.ISOID = ISO_Stats.ISOID) AND (ISO_ID.InstNbr = ISO_Stats.InstNbr))
    INNER JOIN ISO_Stats AS m3
    ON ISO_ID.[ISOID] = m3.[ISOID])
WHERE
        (((ISO_Stats.MonthEnd)=DateSerial(Year(Date()),Month(Date()),0))
    AND ((m2.MonthEnd)=DateSerial(Year(Date()),Month(Date())-1,0))
    AND ((m3.MonthEnd)=DateSerial(Year(Date()),Month(Date())-2,0))
    AND ((ISO_ID.Cancelled)<>"Y") )
ORDER BY ISO_ID.ISOName;

1 个答案:

答案 0 :(得分:1)

您的查询的SELECT列列表包含重复的列名称。使用别名,以便查询结果集中的列名称是不同的:

SELECT
    ISO_ID.ISOID,
    ISO_Stats.TransactionCount AS [TransactionCount_i],
    ISO_Stats.TerminalCount AS [TerminalCount_i],
    ISO_Stats.MonthEnd AS [MonthEnd_i],
    m2.TerminalCount AS [TerminalCount_2],
    m2.TransactionCount AS [TransactionCount_2],
    m2.MonthEnd AS [MonthEnd_2],
    m3.TerminalCount AS [TerminalCount_3],
    m3.TransactionCount AS [TransactionCount_3],
    m3.MonthEnd AS [MonthEnd_3]

您需要修改报告以使用这些别名列名,但是在处理重复的列名时,您应该能够避免报告的混淆。