Domanda

Ho bisogno di aiuto per convertire questa query T-SQL in MS Access.L'errore che sto ottenendo è unisciti all'espressione non supportata.

Aggiornamento:

Non posso aggiungere:

DDA su TT. [Descrizione]= DDA.AccountTypedped e H.AccountNumber= DDA.AccountNumber

ma

DDA su Tt. [Descrizione]= DDA.AccountTypedped

funziona.C'è un modo per aggiungere la seconda condizione?

T-SQL Query:

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
.

Modifica: ho sostituito la query con la parola chiave come.Ho fatto lo stesso errore. MS Access Query con errore:

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                   
.

Ecco la query semplificata con lo stesso errore:

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                   
.

È stato utile?

Soluzione

Riferirsi a provare a Converti il testo SQL dalla tua query T-SQL per accedere a SQL. Creare una nuova query di accesso da zero e utilizza la query T-SQL solo come una mappa stradale. Aggiungi le tue origini dati e configura i join. Il designer di query ti garantirà di creare i join nel modo che mantiene il motore DB felice: aggiunta e posizionamento delle parentesi richiede per query con più di un join; le regole che si applicano per i join sinistro; e così via. Lascia che il designer maneggi i dettagli per te.

Il progettista soffocherà in Design View a causa delle funzioni in questa parte del tuo ultimo join:

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

Quindi lascia le funzioni RTRIM() mentre stai configurando i join nella vista Design. Non preoccuparti che la query non renda i risultati corretti. Dopo aver ottenuto i join che soddisfano il motore DB, passare alla vista SQL e aggiungi le funzioni RTRIM() in.

Dopo aver impostato correttamente i join, aggiungi le espressioni del campo all'elenco SELECT.

Inoltre è possibile trovare più facile gestire la tua query complessa scoppiando i sottostibiettivi come query salvate separate --- quindi fare riferimento a quelle query per nome nella query master proprio come si aggiungerebbero sorgenti.

Altri suggerimenti

Il problema è con la penultima linea:

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

La vista di progettazione del progettista di query di accesso non può funzionare con le funzioni nella parte ON della clausola.È necessario rimuovere il RTRIM.

L'accesso è felice delle parentesi.Avvolgi ogni espressione di unione tra parentesi, le clausole da sole e ogni coppia di tavoli.

Non è possibile utilizzare convertire, NOLOCK o Case.

Quale versione di MSAccess utilizzi nel tuo sistema?Ho appena provato nella versione 2007 e Rtrim funziona.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top