What is the best practice to get the date from a smalldatetime field without the time.
The table contains 5 minute readings for energy consumption in the column period.
Now i need to get all the readings form some dates.
SELECT dbo.TBL_Data.*
FROM dbo.TBL_Data
WHERE (Period IN (CONVERT(DATETIME, '2003-12-31', 102), CONVERT(DATETIME, '2004-01-01', 102)))
this result contains only the readings for the timestamp 00:00
so how to select the whole day ?
kind regards
piet1. "IN" keyword only checks if the values are EQUAL to any of the values listed, not in between the two values (check for the BETWEEN operator or use a combination of greater-than and less-than), and
2. Also try explicitly setting the time value for each convert (check my syntax) so that you don't rely on the default time setting:
WHERE Period > CONVERT(DATETIME, '2003-12-31 00:00:00', 102) AND Period < CONVERT(DATETIME, '2003-12-31 12:59:59', 102)
No comments:
Post a Comment