Tuesday, March 20, 2012

Adding 0 to a column

Hi

I have a column with times in

845

930

1015

1145

I need to update the column to look like this:

08:45

09:30

10:15

11:45

thanks in advance

rich

Maybe something like:

set nocount on

declare @.timeSample table (aTime integer not null)

insert into @.timeSample values (845)
insert into @.timeSample values (930)
insert into @.timeSample values (1015)
insert into @.timeSample values (1145)

select right ('0' + convert (varchar (2), aTime / 100),2) + ':' +
convert (char(2), aTime % 100) as formattedTime
from @.timeSample

-- --
-- SAMPLE OUTPUT:
-- --


-- formattedTime
-- -
-- 08:45
-- 09:30
-- 10:15
-- 11:45

sql

No comments:

Post a Comment