Create Time String
USE: This function will return a string representation of time.
CREATE FUNCTION [dbo].[fnCreateTimeString] ( @seconds int) RETURNS varchar(75) AS BEGIN DECLARE @h int, @m int, @s int, @secs int, @BuildDate varchar(75), @hour varchar(75), @minute varchar(50), @second varchar(25) SELECT @secs = @seconds SELECT @h = @secs / 3600 SELECT @secs = @secs - (@h * 3600) SELECT @m = @secs / 60 SELECT @secs = @secs - (@m * 60) SELECT @s = @secs SELECT @second = CASE WHEN @s = 1 THEN CAST(@s AS varchar) +' second' ELSE CAST(@s AS varchar) +' seconds' END SELECT @minute = CASE WHEN @m = 1 THEN CAST(@m AS varchar) +' minute with '+ @second ELSE CAST(@m AS varchar) +' minutes with '+ @second END SELECT @hour = CASE WHEN @h = 1 THEN CAST(@h AS varchar) +' hour '+ @minute + @second ELSE CAST(@h AS varchar) +' hours '+ @minute + @second END IF @h = 0 BEGIN IF @m = 0 BEGIN SELECT @BuildDate = @second END ELSE BEGIN SELECT @BuildDate = @minute END END ELSE BEGIN SELECT @BuildDate = @hour END RETURN CONVERT(varchar(75), @BuildDate) END GO