Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

the SQL,
SQL
SELECT CONVERT(VARCHAR(10), VRS_UTCTIME, 121) AS [Date],
MIN(SUBSTRING(CONVERT(VARCHAR(23), VRS_UTCTIME, 121), 12,20)) AS [start_time],
MAX(SUBSTRING(CONVERT(VARCHAR(23), VRS_UTCTIME, 121), 12,20)) AS [stop_time],
MAX(VRS_SPEED) AS [max_speed]
FROM STS_VEHICLE_RUNNING_STATUS
WHERE VRS_DEVICEID = 'ST0001' AND  VRS_UTCTIME BETWEEN '2012-07-02' AND '2012-11-09'
GROUP BY CONVERT(VARCHAR(10), VRS_UTCTIME, 121)

retrieve data as below,
Date            start_time      stop_time       max_speed
----            ----------      ---------       ---------
2012-07-02      10:59:26.000    11:33:36.000    40

2012-09-06      18:45:29.000    19:46:28.000    0.36

2012-10-09      12:10:12.000    01:12:12.000    50

Then, how can remove the SS(HH:MM:SS) part of start_time and stop_time using SQL?

Thanks..
Posted
Updated 21-Nov-12 21:50pm
v3

Change the length from 20 to 5 in your SUBSTRING function calls.
 
Share this answer
 
Comments
hasbina 22-Nov-12 4:08am    
Thank you sir..
OriginalGriff 22-Nov-12 4:10am    
You're welcome!
Can you please try this one...

SQL
SELECT CONVERT(VARCHAR(10), VRS_UTCTIME, 121) AS [Date],
MIN(LEFT(CONVERT(VARCHAR(8),VRS_UTCTIME, 108),5)) AS [start_time],
MAX(LEFT(CONVERT(VARCHAR(8),VRS_UTCTIME, 108),5)) AS [stop_time],
MAX(VRS_SPEED) AS [max_speed]
FROM STS_VEHICLE_RUNNING_STATUS
WHERE VRS_DEVICEID = 'ST0001' AND  VRS_UTCTIME BETWEEN '2012-07-02' AND '2012-11-09'
GROUP BY CONVERT(VARCHAR(10), VRS_UTCTIME, 121)
 
Share this answer
 
Comments
hasbina 22-Nov-12 4:07am    
Thank you sir..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900