July 25th, 2013, 10:15 AM
Join Date: Jul 2013
Time spent in forums: 1 h 43 m 28 sec
Reputation Power: 0
Trouble with Having clause
I Need a query to get the value for the first day of each month at 7am for a fiscal year. Here is what I have.
SELECT Value as ELEVATION,
DATEPART(Month, DateTime) AS EMONTH,
DATEPART(Year, DateTime) AS EYEAR,
DATEPART(Day, DateTime) as DAY,
DATEPART(Hour, DateTime) as HOUR
WHERE TagName = 'ScituateGDGHReservoir.Level' AND
DateTime > '06/30/2012 11:59:59PM' AND
DateTime < '07/01/2013 12:00:00AM'
GROUP BY Value, DateTime
HAVING DatePart(Day, DateTime) = '1' AND DATEPART(Hour, DateTime) = '7'
ORDER BY EYEAR Asc, EMONTH Asc, DAY asc;
When I run it I get nothing.
But when I run this query
SELECT * FROM Runtime.dbo.AnalogHistory WHERE DateTime = '07/01/2012 7:00:00AM' AND TagName = 'ScituateGDGHReservoir.Level' ORDER BY DateTime ASC
I get a result.