SQL Server Performance

Convert VarChar to Time

Discussion in 'SQL Server 2008 General Developer Questions' started by baburk, Mar 12, 2009.

  1. baburk New Member

    The below query returns


    SELECT REPLACE( RIGHT( REPLICATE('0',5 - LEN(5)) + CONVERT(VARCHAR(18), RB.Batch), 5) + '.00', '.', ':')
    FROM RunningBatch AS RB

    80:00:00
    70:00:00
    08:02:00
    10:00:00
    06:00:00


    How can I able to cast this to sys.Time

    Thanks

  2. FrankKalis Moderator

    How should 80:00:00 be interpreted? Does it mean 80 hours?
  3. baburk New Member

    Sorry now it is
    within 24 hours
    SELECT CAST( CONVERT(VARCHAR(18), REPLACE( RIGHT( REPLICATE('0',5 - LEN(5)) + CONVERT(VARCHAR(18), VRB.VHRBatchHrsKm), 5) + '00', '.', '')) AS sys.time)
    FROM Vehicle.VehicleRunningBatch AS VRB
    I got
    Conversion failed when converting date and/or time from character string.

  4. FrankKalis Moderator

    I'm still confused...
    Can you please explain what that values should be interpreted as and what the output should look like?

Share This Page