Create a function as like below:
CREATE FUNCTION [dbo].[ufn_GetHHMM] ( @pInputSecs BIGINT )
RETURNS VARCHAR(MAX)
BEGIN
DECLARE @HHMM Varchar(Max)
IF @pInputSecs < 60 and @pInputSecs<>0
BEGIN
SET @HHMM= '0:01'
END
ELSE
BEGIN
SET @HHMM=ISNULL(CAST(@pInputSecs/3600 AS VARCHAR(MAX)) +':'
+RIGHT('0'+CAST(ROUND(CAST((@pInputSecs%3600.0)/60.0 as float),0) as varchar(MAX)),2),'0:00')
END
RETURN @HHMM
END
--To Get Results
SELECT dbo.ufn_GetHHMM(DurationinSeconds) --Assume you have column name 'DurationinSeconds'
No comments:
Post a Comment