SQL Scripts

List of some useful sql scripts

 1. Time conversion - Seconds to HH MM SS
ALTER    function [dbo].[funSecToHHMMSS] (@sec integer) 
returns varchar(19)
as
begin
declare @DayTime varchar(19)
    SELECT @DayTime = STR(DATEDIFF(hh,0,DATEADD(ss,@sec,0)),5)         --Get the hours
            + RIGHT(CONVERT(CHAR(8),DATEADD(ss,@sec,0),108),6) --Format the rest
Return @DayTime
end