Background: There is a small need to be based on the incoming start and end time, not one hours to count the average data, I thought of the use of stored procedures to achieve.
When SQL is finished, it executes,
Hey ~ How, I did not convert the type of place Ah, is the statement splicing error.
The following is a definition of two time variable formats that are in datetime format,
The problem is in the time-type statement stitching, think of two solutions,
When stitching, the time is changed to the varchar type, or the original time type is defined as the varchar type directly.
Cast () function for type conversion
After the change is completed, one executes
The data has, but a bit wrong ah, I added the test data is one hours a piece of data ah, how there is a row is 0.
After a closer look, there is a problem finding the query time. (Is this the default time format for SQL?)
The two-time data format used for querying in a stored procedure is only accurate to the minute, and the test data that I add myself has a continuous number of hours of data that is 59 minutes in number of seconds, resulting in the computation
Calculate the data for the hour that was supposed to be in the last one hours (I'm glad you added the data to help yourself find a hidden danger AH).
Workaround:
Select CONVERT (varchar), GETDATE (), 25): 2006-05-16 10:57:47.250
Modify the time format.
SQL stored Procedure statement splicing the time type of the sorrow person