2

この T-SQL クエリを MS ACCESS に変換するのに助けが必要です。私が得ているエラーは、サポートされていない JOIN 式です。

アップデート:

追加できません:

DDA ON TT.[説明] = DDA.AccountTypeDesc AND H.AccountNumber = DDA.AccountNumber

しかし

DDA ON TT.[説明] = DDA.AccountTypeDesc

動作します。2番目の条件を追加する方法はありますか?

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                   
4

4 に答える 4

2

SQL テキストを T-SQL クエリから Access SQLに変換するのはあきらめてください。新しい Access クエリを最初から作成し、T-SQL クエリをロード マップとしてのみ使用します。データ ソースを追加し、結合を設定します。クエリ デザイナーは、db エンジンを満足させる方法で結合を作成することを保証します。複数の結合を持つクエリに必要な括弧の追加と配置。LEFT JOIN に適用されるルール。など。これらの詳細はデザイナーに任せてください。

最後の結合のこの部分の関数が原因で、デザイナーはデザイン ビューでチョークします。

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

そのためRTRIM()、デザイン ビューで結合を設定するときは、関数を省略してください。クエリが正しい結果を返さなくても心配しないでください。db エンジンを満たす結合を取得したら、SQL ビューに切り替えて、RTRIM()関数を再度追加します。

結合を正しく設定したら、フィールド式をSELECTリストに追加します。

また、サブクエリを別個の保存されたクエリとして分割することで、複雑なクエリを管理しやすくなる場合があります。次に、テーブル ソースと同様に、マスター クエリでそれらのクエリを名前で参照します。

于 2012-07-27T07:16:23.607 に答える
1

問題は、最後から 2 番目の行にあります。

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

Access クエリ デザイナーのデザイン ビューはON、句の一部の関数を操作できません。を削除する必要がありRTRIMます。

于 2012-07-27T06:46:05.777 に答える
0

アクセスはカッコいいです。各結合式を括弧で囲み、ON 句自体とテーブルの各ペアを囲みます。

CONVERT、NOLOCK、または CASE は使用できません。

于 2012-07-27T07:51:27.797 に答える
0

システムで使用している MSAccess のバージョンは? 2007 バージョンで試してみたところ、RTRIM が機能しています。

于 2012-07-27T06:53:39.750 に答える