多标识符错误在Excel 2007中MS查询,但没有在SQL Server 2008(Multipa

2019-09-29 06:24发布

我有以下SQL代码

SELECT pd1.Meter,
       pd1.BasicPool,
       pd1.RateClass,
       pd1.Flowdate,
       (SELECT upOrDownContract
        FROM   PipelineData pd
        WHERE  pd.id = pd1.sibling) AS DnK,
       match.Volume,
       (SELECT Name
        FROM   Pipeline P
        WHERE  P.id = ISNULL(pd2.pipelineID, t.PipelineId)) AS Pipeline,
       (SELECT Name
        FROM   Client C
        WHERE  C.id = t.ClientId)                           AS CounterParty
FROM   MatchingHistoryBothSides match
       LEFT JOIN PipelineData pd1
              ON match.type1 = 'PipelineDataVO'
                 AND match.id1 = pd1.ID
       LEFT JOIN PipelineData pd2
              ON match.type2 = 'PipelineDataVO'
                 AND match.id2 = pd2.ID
       LEFT JOIN TransactionDailyVolume dtv
              ON match.type2 = 'TransactionDailyVolumeVO'
                 AND match.id2 = dtv.ID
       LEFT JOIN [Transaction] t
              ON dtv.TransactionID = t.ID
WHERE  match.type1 = 'PipelineDataVO'
       AND ( match.type2 = 'PipelineDataVO'
              OR match.type2 = 'TransactionDailyVolumeVO' )
       AND pd1.flowDate BETWEEN ? AND ?
       AND pd1.LDCid = 75
       AND pd1.direction = 'Receipt' 

它工作正常,在SQL Sever的2008年,但给[Microsoft][ODBC SQL Server Driver][SQL Server]The multi-part identifier "pd1.flowDate" could not be bound在Excel 2007中MS查询谁能解释这哪里是代码走错了?

Answer 1:

在子查询Select在MS查询是不允许的。 因此在去除子查询,并让他们为连接将在MS查询工作。 下面的代码在MS查询

SELECT pd1.Meter,
       pd1.BasicPool,
       pd1.RateClass,
       pd1.FlowDate,
       pd.upOrDownContract AS dnk,
       match.Volume,
       p.Name              AS pipeline,
       c.Name              AS counterparty
FROM   Matchinghistorybothsides match
       LEFT JOIN Pipelinedata pd1
              ON match.type1 = 'PipelineDataVO'
                 AND match.id1 = pd1.ID
       LEFT JOIN Pipelinedata pd2
              ON match.type2 = 'PipelineDataVO'
                 AND match.id2 = pd2.ID
       LEFT JOIN Transactiondailyvolume dtv
              ON match.type2 = 'TransactionDailyVolumeVO'
                 AND match.id2 = dtv.ID
       LEFT JOIN [Transaction] t
              ON dtv.TransactionID = t.ID
       LEFT JOIN Client c
              ON c.id = t.ClientId
       LEFT JOIN Pipelinedata pd
              ON pd.id = pd1.sibling
       LEFT JOIN Pipeline p
              ON p.id = COALESCE(pd2.PipelineId, t.PipelineId)
WHERE  match.type1 = 'PipelineDataVO'
       AND ( match.type2 = 'PipelineDataVO'
              OR match.type2 = 'TransactionDailyVolumeVO' )
       AND pd1.FlowDate BETWEEN ? AND ?
       AND pd1.LDCid = 75
       AND pd1.direction = 'Receipt'


文章来源: Multipart identifier error in Excel 2007 MS Query but not in SQL Server 2008