I have the following SQL code
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'
It works fine in SQL Sever 2008 but gives [Microsoft][ODBC SQL Server Driver][SQL Server]The multi-part identifier "pd1.flowDate" could not be bound
in MS Query of Excel 2007. Can anyone explain where this code is going wrong?
Sub queries in
Select
are not allowed in MS Query. Hence on removal of the the sub queries and making them as joins will work in MS Query. The following code works in MS Query