Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Time

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2014-12-04 : 04:53:20

i have column that show the time but in format int
how i show it in this format

TimeCol
1600
730
0

TimeCol
16:00
07:30
0

sunder.bugatha
Yak Posting Veteran

66 Posts

Posted - 2014-12-04 : 06:49:38
SELECT (CASE WHEN LEN(TIMECOL)=4 THEN SUBSTRING(TIMECOL,1,2)+':'+SUBSTRING(TIMECOL,3,2)
WHEN LEN(TIMECOL)=3 THEN '0'+SUBSTRING(TIMECOL,1,1)+':'+SUBSTRING(TIMECOL,2,2)
ELSE TIMECOL
END)
FROM test1


Hema Sunder
Go to Top of Page

sunder.bugatha
Yak Posting Veteran

66 Posts

Posted - 2014-12-04 : 06:55:20
replace Timecol with CONVERT(VARCHAR(10),TIMECOL) if it is an integer

Hema Sunder
Go to Top of Page
   

- Advertisement -