Search code examples
sql-servert-sqltimesql-server-2005date-conversion

Convert float 8.07 to string as 08:07 in SQL Server 2005


I want to convert the float time field 8.07 to string 08:07. Is there any easy way to do this? Or Should I split it by dot, calculate the length and append zero accordingly?


Solution

  • What about this:

    DECLARE @value DECIMAL(9,2) = 8.07
    
    SELECT REPLACE(RIGHT(@value  + 1000000, 5), '.', ':');
    

    Of course you can change the value you are adding to something small.