欧博百家乐How to convert INTEGER to TIME – SQLSer
February 16, 2009 at 12:36 pm
Then, the easiest way to handle things like leading zeros and the like, is to let SQL Server do it all for you...
SELECT RIGHT(CONVERT(CHAR(8),DATEADD(s,Seconds,0),108),5)
FROM (--==== Your table name would go here.... this is just for demo...
SELECT 1 AS Seconds UNION ALL
SELECT 10 UNION ALL
SELECT 100 UNION ALL
SELECT 1000 UNION ALL
SELECT 2000 UNION ALL
SELECT 3000 UNION ALL
SELECT 3599
) yourtable
Micheal Earl's method is probably better, though... if it does go over 3559 seconds, his will show minutes over 60. Mine is probably a bit faster because it has one less CONVERT, but it will not accomodate times over 59:59 and it will not warn you.
--Jeff Moden RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
Change is inevitable... Change for the better is not.
Helpful Links:
How to post code problems
How to Post Performance Problems
Create a Tally Function (fnTally)