Convert Seconds to Hour: Minute: Seconds Format in Sql Server

 Admin   
33 View    Nov 16 2020 5:45PM

CREATE FUNCTION [dbo].[Fn_SecondsToHours]  

 (  

@Sec VARCHAR(MAX)  

)  

RETURNS VARCHAR(MAX)  

BEGIN  

DECLARE @op VARCHAR(MAX)  

SET @op = ''  

SELECT @op=RIGHT('0' + CAST(@Sec  / 3600 AS VARCHAR),2) + ':' +  

RIGHT('0' + CAST((@Sec  / 60) % 60 AS VARCHAR),2) + ':' +  

RIGHT('0' + CAST(@Sec  % 60 AS VARCHAR),2) 

RETURN @op  

End 

GO

SELECT [dbo].[Fn_SecondsToHours]('100'