-- =============================================
-- Author:Sabah u din Irfan
-- Create date: July/1/2009
-- Description: A UDF to convert the seconds into MM:SS
-- Example: select [dbo].[fn_SEC2MIN](36)
-- print dbo.fn_SEC2MIN ( 36045)
-- =============================================
CREATE FUNCTION [dbo].[fn_SEC2MIN]( @Sec as int )
RETURNS VARCHAR (15)
AS
BEGIN
DECLARE @return AS VARCHAR (15)
DECLARE @i_MM as INT
DECLARE @i_SS as INT
SET @i_MM=0
SET @i_SS=0
SET @return = '00:00'
IF ( @SEC >= 60 )
BEGIN
SET @i_MM = FLOOR(@Sec / 60 )
SET @i_SS = @Sec % 60
END
ELSE
BEGIN
SET @i_SS = @Sec
END
SET @return = case len(cast( @i_MM AS Varchar)) when 1 then right('00' + cast( @i_MM AS Varchar), 2 ) else cast( @i_MM AS Varchar) end +':'+ right('00' + cast( @i_SS AS Varchar), 2 )
RETURN @return
END
No comments:
Post a Comment