• By converting the time strings to datetime values, you can do the following.

    /* I'm assuming here that @TimeString1 always represents the earlier time and @TimeString2 the later time */

    DECLARE @TimeString1 char(6)

    DECLARE @TimeString2 char(6)

    SELECT @TimeString1 = '133737', @TimeString2 = '154040'

    /* Insert ':' characters to format as 'HH:MM:SS' and implicitly convert strings to datetime values */

    DECLARE @Time1 datetime

    DECLARE @Time2 datetime

    SELECT @Time1 = STUFF(STUFF(@TimeString1, 5, 0, ':'), 3, 0, ':'),

    @Time2 = STUFF(STUFF(@TimeString2, 5, 0, ':'), 3, 0, ':')

    /* Determine time difference as a datetime value relative to value 0 (1900-01-01 00:00:00.000). Note that if @Time1 > @Time2 then the result of the DATEDIFF function call is negative. In this case, it is assumed that the two times span a day boundary so 24 * 60 * 60 = 86400 seconds need to be added to get the true elapsed time. */

    DECLARE @ElapsedTime datetime

    SELECT @ElapsedTime = DATEADD(second, DATEDIFF(second, @Time1, @Time2) + CASE WHEN (@Time1 > @Time2) THEN 86400 ELSE 0 END, 0)

    /* Finally display elapsed time using CONVERT format 108 */

    SELECT CONVERT(char(8), @ElapsedTime, 108)

    If elapsed times equal or exceed 24 hours then the above method won't work and you will need to consider dates as well.

    It would have been simpler and more efficient to store the times as datetime values in the table, and if you are storing the date in a separate column, then it would probably be better to store the date and time combined in a single datetime column as well.