比较日期格式化为hh:mm:ss(看着头痛)

SELECT    [Car] ,
                        DeviceNo ,
                        MIN([StateTime]) [StateTime] ,
                        MAX([EndTime]) [EndTime] ,
                        CAST(( DATEDIFF(SS, MIN([StateTime]), MAX([EndTime]))
                               / 3600 ) AS VARCHAR(12)) + ':'
                        + CAST(( ( DATEDIFF(SS, MIN([StateTime]),
                                            MAX([EndTime])) - ( DATEDIFF(SS,
                                                              MIN([StateTime]),
                                                              MAX([EndTime]))
                                                              / 3600 ) * 3600 )
                                 / 60 ) AS VARCHAR(12)) + ':'
                        + CAST(( DATEDIFF(SS, MIN([StateTime]), MAX([EndTime]))
                                 - ( DATEDIFF(SS, MIN([StateTime]),
                                              MAX([EndTime])) / 3600 ) * 3600 )
                        - ( ( DATEDIFF(SS, MIN([StateTime]), MAX([EndTime]))
                              - ( DATEDIFF(SS, MIN([StateTime]),
                                           MAX([EndTime])) / 3600 ) * 3600 )
                            / 60 ) * 60 AS VARCHAR(12)) [datediff]
              FROM      [GPSTest].[dbo].[GPS_AccFire]
              WHERE     CAr = '粤S0972学'
              GROUP BY  [Car] ,
                        DeviceNo

posted @ 2012-04-18 11:58  qanholas  阅读(695)  评论(0编辑  收藏  举报