Consider the following select:
SELECT *
FROM v_AnalogHistory
INNER JOIN (SELECT TOP 1 NaedChange.NaedID,NaedChange.Datetime,RPMSetupProd.dbo.Naed.Name
FROM RPMViewProd.dbo.NaedChange AS NaedChange
LEFT OUTER JOIN RPMSetupProd.dbo.Naed ON RPMSetupProd.dbo.Naed.ID = NaedChange.NaedID
WHERE NaedChange.Line = 'Ligne 3' AND NaedChange.Datetime <= '2004/03/26 07:45'
ORDER BY NaedChange.Datetime DESC) AS Naed ON Naed.Datetime <= v_AnalogHistory.Datetime
WHERE v_AnalogHistory.Tagname = 'L1_Sealer_TEMP_F'
AND v_AnalogHistory.Datetime >= DateAdd(n,-15,getDate())
In the WHERE section of the "SELECT TOP 1" I need to change NaedChange.Datetime <= '2004/03/26 07:45' to NaedChange.Datetime <= v_AnalogHistory.Datetime but if make taht change it gives me the error : "The column prefix 'v_AnalogHistory' does not match with a table name or alias name used in the query."
How can use v_AnalogHistory.Datetime inside my other select?
I tried using an alias for v_AnalogHistory and it did the same error.