I have some SQL which runs fine without the HAVING clause, yet when I uncomment either of the HAVING clause versions in the SQL it errors.
Line #9 gives an error of :
Msg 207, Level 16, State 1, Line 9
Invalid column name 'MaxDate'.
Line #10 gives an error of :
Msg 102, Level 15, State 1, Line 10
Incorrect syntax near '#'.
My SQL experience is mainly in Access so I do struggle in areas where that differs from T-SQL. I'm getting there, but I cannot for the life of me, see why this is reacting as it is. It all seems fine to me. Clearly my eyes need some more experience.
If anyone can throw any light then I'd be grateful.
Code:
SELECT TOP 10
[OH_LEDGER]
,CAST(Max([OH_ENTERED_DATE]) AS DateTime) AS [MaxDate]
FROM [Progress].[dbo].[ORDER_HEADERS]
GROUP BY [OH_LEDGER]
--HAVING ([MaxDate]<Cast('2010-02-10' AS DateTime))
--HAVING ([MaxDate]<#02/10/2010#)
ORDER BY [MaxDate] DESC
GO
Msg 207, Level 16, State 1, Line 9
Invalid column name 'MaxDate'.
Line #10 gives an error of :
Msg 102, Level 15, State 1, Line 10
Incorrect syntax near '#'.
My SQL experience is mainly in Access so I do struggle in areas where that differs from T-SQL. I'm getting there, but I cannot for the life of me, see why this is reacting as it is. It all seems fine to me. Clearly my eyes need some more experience.
If anyone can throw any light then I'd be grateful.
Comment