Question

I have the following statement in MS ACCESS that retrieves 0 data and should retrieve 1 value since qselSumPastDivs_vd retrieves 1 value:

SELECT tblTrades.Tick, 
   IIf([tblTrades].[vd_off]>Now(), [qselSumPastDivs_vd].[SumOfBBG_Div_Forecast],
                                   [qselSumOfPastDivs].[SumOfBBG_Div_Forecast]) AS Expr1
FROM ((tblBbgDivData INNER JOIN 
      tblTrades ON tblBbgDivData.Tick = tblTrades.Tick) INNER JOIN 
      qselSumOfPastDivs ON tblTrades.Tick = qselSumOfPastDivs.Tick) INNER JOIN 
      qselSumPastDivs_vd ON tblTrades.Tick = qselSumPastDivs_vd.Tick
GROUP BY tblTrades.Tick, 
         IIf([tblTrades].[vd_off]>Now(), [qselSumPastDivs_vd].[SumOfBBG_Div_Forecast],
                                         [qselSumOfPastDivs].[SumOfBBG_Div_Forecast]);

Is it the joints that are generating the problem?

I have removed the [] in the IIF statement but apparently, MS ACCESS requires the () for the multiple INNER JOIN. Still no data...

SELECT tblTrades.Tick, IIf(tblTrades.vd_off>Now(),qselSumPastDivs_vd.SumOfBBG_Div_Forecast,qselSumOfPastDivs.SumOfBBG_Div_Forecast) AS Expr1
FROM ((tblBbgDivData INNER JOIN tblTrades ON tblBbgDivData.Tick = tblTrades.Tick) INNER JOIN qselSumOfPastDivs ON tblTrades.Tick = qselSumOfPastDivs.Tick) INNER JOIN qselSumPastDivs_vd ON tblTrades.Tick = qselSumPastDivs_vd.Tick
GROUP BY tblTrades.Tick, IIf(tblTrades.vd_off>Now(),qselSumPastDivs_vd.SumOfBBG_Div_Forecast,qselSumOfPastDivs.SumOfBBG_Div_Forecast);
Was it helpful?

Solution

Changing the JOIN from INNER JOIN to LEFT JOIN did the job:

SELECT tblTrades.Tick, IIf([tblTrades].[vd_off]>Now(),[qselSumPastDivs_vd].[SumOfBBG_Div_Forecast],[qselSumOfPastDivs].[SumOfBBG_Div_Forecast]) AS DivLevel2
FROM ((tblTrades INNER JOIN tblBbgDivData ON tblTrades.Tick = tblBbgDivData.Tick) LEFT JOIN qselSumOfPastDivs ON tblTrades.Tick = qselSumOfPastDivs.Tick) LEFT JOIN qselSumPastDivs_vd ON tblTrades.Tick = qselSumPastDivs_vd.Tick
GROUP BY tblTrades.Tick, IIf([tblTrades].[vd_off]>Now(),[qselSumPastDivs_vd].[SumOfBBG_Div_Forecast],[qselSumOfPastDivs].[SumOfBBG_Div_Forecast]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top