我需要帮助将此 T-SQL 查询转换为 MS ACCESS。我收到的错误是不支持 JOIN 表达式。

更新:

我无法添加:

dda on tt。[description] = dda.accounttypedesc和h.accountnumber = dda.accountnumber

DDA ON TT.[描述] = DDA.AccountTypeDesc

作品。有没有办法添加第二个条件?

T-SQL 查询:

SELECT
    *
FROM
(
    SELECT
        [PesoAmount] = CASE WHEN FE.IsoCode IS NULL THEN
            LTRIM(STR(DFCF.CurrencyAmount, 20, 2))
        ELSE
            LTRIM(STR(DFCF.CurrencyAmount * FE.PhpConversionRate, 20, 2))
        END,
        DFCF.TransactionNumber,
        DFCF.AccountNumber,
        DFCF.CountryCd,
        DFCF.TransactionTypeCd,
        DFCF.Time,
        DFCF.Date,
        DFCF.TransactionStatusCd,
        DFCF.TransactionCurrencyCd,
        DFCF.BranchNumber,
        DFCF.RemitterExtPartyCd,
        DFCF.BeneficiaryExtPartyCd,
        DFCF.PostedDate,
        DFCF.AssociateNumber,
        DFCF.ExecutingPartyNumber,
        DFCF.CurrencyAmount,
        DFCF.CurrencyAmountInTxnCcy,
        DFCF.CurrencyAmountInAccountCcy,
        DFCF.SecondaryAccountKey,
        DFCF.RelatedInd,
        DFCF.ThirdPartyInd,
        DFCF.TransactionDescription,
        DFCF.SecurityName,
        DFCF.DealNumber
    FROM
        dbo.DesFactCashFlow DFCF (NOLOCK)                                            LEFT JOIN
        dbo.ForeignExchange   FE (NOLOCK) ON DFCF.TransactionCurrencyCd = FE.IsoCode
)
                           H                                                                                          LEFT JOIN
    dbo.Ctr                C (NOLOCK) ON H.PesoAmount                           = C.PesoAmountFaceValueSumInsured AND
                                         H.AccountNumber                        = C.AccountNumber                 AND
                                         H.TransactionTypeCd                    = C.TransactionType                   LEFT JOIN
    dbo.TransactionType   TT (NOLOCK) ON H.TransactionTypeCd                    = TT.Code                             LEFT JOIN
(
    SELECT
        [AccountNumber]               = DDA2.AccountNumber,
        [AccountTypeDesc]             = DDA2.AccountTypeDesc,
        [LineOfBusinessName]          = MAX(DDA2.LineOfBusinessName),
        [AccountCurrencyCode]         = MAX(DDA2.AccountCurrencyCode),
        [AccountCurrencyName]         = MAX(DDA2.AccountCurrencyName),
        [AccountRegistrationTypeDesc] = MAX(DDA2.AccountRegistrationTypeDesc),
        [AccountRegistrationName]     = MAX(DDA2.AccountRegistrationName),
        [AccountName]                 = MAX(DDA2.AccountName),
        [AlternateName]               = MAX(DDA2.AlternateName),
        [AccountOpenDate]             = MAX(DDA2.AccountOpenDate),
        [AccountCloseDate]            = MAX(DDA2.AccountCloseDate),
        [AccountStatusDesc]           = MAX(DDA2.AccountStatusDesc),
        [DormantInd]                  = MAX(DDA2.DormantInd),
        [ProductLineName]             = MAX(DDA2.ProductLineName),
        [ProductCategoryName]         = MAX(DDA2.ProductCategoryName),
        [ProductTypeName]             = MAX(DDA2.ProductTypeName),
        [ProductName]                 = MAX(DDA2.ProductName),
        [ProductNumber]               = MAX(DDA2.ProductNumber),
        [AccountTaxId]                = MAX(DDA2.AccountTaxId),
        [AccountTaxIdTypeCode]        = MAX(DDA2.AccountTaxIdTypeCode),
        [AccountTaxStateCode]         = MAX(DDA2.AccountTaxStateCode),
        [AccountPrimaryBranchName]    = MAX(DDA2.AccountPrimaryBranchName),
        [MailingAddress1]             = MAX(DDA2.MailingAddress1),
        [MailingAddress2]             = MAX(DDA2.MailingAddress2),
        [MailingCityName]             = MAX(DDA2.MailingCityName),
        [MailingStateCode]            = MAX(DDA2.MailingStateCode),
        [MailingStateName]            = MAX(DDA2.MailingStateName),
        [MailingPostalCode]           = MAX(DDA2.MailingPostalCode),
        [MailingCountryCode]          = MAX(DDA2.MailingCountryCode),
        [MailingCountryName]          = MAX(DDA2.MailingCountryName),
        [CurrencyBasedAccountInd]     = MAX(DDA2.CurrencyBasedAccountInd),
        [MaturityDate]                = MAX(DDA2.MaturityDate),
        [OriginalLoanAmount]          = MAX(DDA2.OriginalLoanAmount),
        [CollateralTypeDesc]          = MAX(DDA2.CollateralTypeDesc),
        [CollateralTypeCode]          = MAX(DDA2.CollateralTypeCode),
        [InsuredAmount]               = MAX(DDA2.InsuredAmount),
        [EmployeeInd]                 = MAX(DDA2.EmployeeInd)
    FROM
        dbo.DesDimAccount DDA2 (NOLOCK)
    GROUP BY
        DDA2.AccountNumber,
        DDA2.AccountTypeDesc
)
                         DDA          ON RTRIM(TT.[Description])                = RTRIM(DDA.AccountTypeDesc)      AND
                                         H.AccountNumber                        = DDA.AccountNumber

编辑:我用 AS 关键字替换了查询。我犯了同样的错误。MS Access 查询出错:

SELECT
    'H'                           AS [HeaderRecordIndicator],
    '1'                           AS [SupervisingAgency],
    '0' + I.InstitutionCode       AS [InstitutionCode],
    CONVERT(char(8), H.Date, 112) AS [ReportDate],
    'CTR'                         AS [ReportType],
    '21'                          AS [FormatCode],
    '1'                           AS [SubmissionType]
FROM
(((
    SELECT
        IIF(ISNULL(FE.IsoCode), FORMAT(DFCF.CurrencyAmount, "##################.00"), FORMAT(DFCF.CurrencyAmount * FE.PhpConversionRate, "##################.00")) AS [PesoAmount],
        DFCF.TransactionNumber,
        DFCF.AccountNumber,
        DFCF.CountryCd,
        DFCF.TransactionTypeCd,
        DFCF.Time,
        DFCF.Date,
        DFCF.TransactionStatusCd,
        DFCF.TransactionCurrencyCd,
        DFCF.BranchNumber,
        DFCF.RemitterExtPartyCd,
        DFCF.BeneficiaryExtPartyCd,
        DFCF.PostedDate,
        DFCF.AssociateNumber,
        DFCF.ExecutingPartyNumber,
        DFCF.CurrencyAmount,
        DFCF.CurrencyAmountInTxnCcy,
        DFCF.CurrencyAmountInAccountCcy,
        DFCF.SecondaryAccountKey,
        DFCF.RelatedInd,
        DFCF.ThirdPartyInd,
        DFCF.TransactionDescription,
        DFCF.SecurityName,
        DFCF.DealNumber
    FROM
        DesFactCashFlow DFCF                                            LEFT JOIN
        ForeignExchange   FE ON DFCF.TransactionCurrencyCd = FE.IsoCode
) AS
                       H                                                                                 LEFT JOIN
    Ctr                C ON H.PesoAmount                           = C.PesoAmountFaceValueSumInsured AND
                            H.AccountNumber                        = C.AccountNumber                 AND
                            H.TransactionTypeCd                    = C.TransactionType)                   LEFT JOIN
    TransactionType   TT ON H.TransactionTypeCd                    = TT.Code)                             LEFT JOIN
(
    SELECT
        DDA2.AccountNumber                    AS [AccountNumber],
        DDA2.AccountTypeDesc                  AS [AccountTypeDesc],
        MAX(DDA2.LineOfBusinessName)          AS [LineOfBusinessName],
        MAX(DDA2.AccountCurrencyCode)         AS [AccountCurrencyCode],
        MAX(DDA2.AccountCurrencyName)         AS [AccountCurrencyName],
        MAX(DDA2.AccountRegistrationTypeDesc) AS [AccountRegistrationTypeDesc],
        MAX(DDA2.AccountRegistrationName)     AS [AccountRegistrationName],
        MAX(DDA2.AccountName)                 AS [AccountName],
        MAX(DDA2.AlternateName)               AS [AlternateName],
        MAX(DDA2.AccountOpenDate)             AS [AccountOpenDate],
        MAX(DDA2.AccountCloseDate)            AS [AccountCloseDate],
        MAX(DDA2.AccountStatusDesc)           AS [AccountStatusDesc],
        MAX(DDA2.DormantInd)                  AS [DormantInd],
        MAX(DDA2.ProductLineName)             AS [ProductLineName],
        MAX(DDA2.ProductCategoryName)         AS [ProductCategoryName],
        MAX(DDA2.ProductTypeName)             AS [ProductTypeName],
        MAX(DDA2.ProductName)                 AS [ProductName],
        MAX(DDA2.ProductNumber)               AS [ProductNumber],
        MAX(DDA2.AccountTaxId)                AS [AccountTaxId],
        MAX(DDA2.AccountTaxIdTypeCode)        AS [AccountTaxIdTypeCode],
        MAX(DDA2.AccountTaxStateCode)         AS [AccountTaxStateCode],
        MAX(DDA2.AccountPrimaryBranchName)    AS [AccountPrimaryBranchName],
        MAX(DDA2.MailingAddress1)             AS [MailingAddress1],
        MAX(DDA2.MailingAddress2)             AS [MailingAddress2],
        MAX(DDA2.MailingCityName)             AS [MailingCityName],
        MAX(DDA2.MailingStateCode)            AS [MailingStateCode],
        MAX(DDA2.MailingStateName)            AS [MailingStateName],
        MAX(DDA2.MailingPostalCode)           AS [MailingPostalCode],
        MAX(DDA2.MailingCountryCode)          AS [MailingCountryCode],
        MAX(DDA2.MailingCountryName)          AS [MailingCountryName],
        MAX(DDA2.CurrencyBasedAccountInd)     AS [CurrencyBasedAccountInd],
        MAX(DDA2.MaturityDate)                AS [MaturityDate],
        MAX(DDA2.OriginalLoanAmount)          AS [OriginalLoanAmount],
        MAX(DDA2.CollateralTypeDesc)          AS [CollateralTypeDesc],
        MAX(DDA2.CollateralTypeCode)          AS [CollateralTypeCode],
        MAX(DDA2.InsuredAmount)               AS [InsuredAmount],
        MAX(DDA2.EmployeeInd)                 AS [EmployeeInd]
    FROM
        DesDimAccount DDA2
    GROUP BY
        DDA2.AccountNumber,
        DDA2.AccountTypeDesc
) AS
                         DDA          ON RTRIM(TT.[Description])                = RTRIM(DDA.AccountTypeDesc)      AND
                                         H.AccountNumber                        = DDA.AccountNumber                   

这是具有相同错误的简化查询:

SELECT
    *
FROM
(((
    SELECT
        IIF(ISNULL(FE.IsoCode), FORMAT(DFCF.CurrencyAmount, "##################.00"), FORMAT(DFCF.CurrencyAmount * FE.PhpConversionRate, "##################.00")) AS [PesoAmount],
        DFCF.TransactionNumber,
        DFCF.TransactionCurrencyCd,
    FROM
        DesFactCashFlow DFCF                                            LEFT JOIN
        ForeignExchange   FE ON DFCF.TransactionCurrencyCd = FE.IsoCode
) AS
                       H                                                                                 LEFT JOIN
    Ctr                C ON H.PesoAmount                           = C.PesoAmountFaceValueSumInsured AND
                            H.AccountNumber                        = C.AccountNumber                 AND
                            H.TransactionTypeCd                    = C.TransactionType)                   LEFT JOIN
    TransactionType   TT ON H.TransactionTypeCd                    = TT.Code)                             LEFT JOIN
(
    SELECT
        DDA2.AccountNumber                    AS [AccountNumber],
        DDA2.AccountTypeDesc                  AS [AccountTypeDesc],
        MAX(DDA2.LineOfBusinessName)          AS [LineOfBusinessName],
    FROM
        DesDimAccount DDA2
    GROUP BY
        DDA2.AccountNumber,
        DDA2.AccountTypeDesc
) AS
                         DDA          ON RTRIM(TT.[Description])                = RTRIM(DDA.AccountTypeDesc)      AND
                                         H.AccountNumber                        = DDA.AccountNumber                   
有帮助吗?

解决方案

放弃尝试从T-SQL查询中转换 SQL文本以访问SQL。从头开始创建新的访问查询,并仅使用T-SQL查询作为路线图。添加您的数据源并设置连接。查询设计器将保证以保留DB引擎的方式创建连接:添加和定位括号,它需要多个连接的查询;申请左路的规则;等等。让设计人员为您处理这些细节。

设计师将扼杀设计视图,由于上次连接的这一部分中的功能:

RTRIM(TT.[Description]) = RTRIM(DDA.AccountTypeDesc)
. 因此,在设置设计视图中的连接时释放RTRIM()函数。别担心查询不会返回正确的结果。获取满足DB引擎的连接后,切换到SQL视图并将RTRIM()函数添加回来。

获取正确设置的加入后,然后将您的字段表达式添加到SELECT列表中。

此外,您可能会通过将子查询作为单独的保存查询(然后按主查询中的名称引用这些查询而更轻松地管理您的复杂查询

其他提示

问题出在倒数第二行:

  DDA ON RTRIM(TT.[Description]) = RTRIM(DDA.AccountTypeDesc) AND

Access 查询设计器的设计视图无法使用 ON 条款的一部分。您必须删除 RTRIM.

访问是括号快乐。将每个连接表达式包装在括号中,对单子句本身以及每对表。

无法使用转换,nolock或案例。

您在系统中使用哪个版本的msaccess?我刚刚尝试在2007年版本和RTRIM工作。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top