February 13, 2014 at 8:40 am
pulling from a ms-dos csv file, time format is just numbers, no ":"
if event time is 145345 it shows as 145345, if it is 23 seconds after midnight it shows as 23
How do I convert or substring it to read 000023?
February 13, 2014 at 8:52 am
You can try this:declare @timevar int
select @timevar = '145345'
select right('000000' + cast(@timevar as varchar(6)), 6)
select @timevar = '23'
select right('000000' + cast(@timevar as varchar(6)), 6)
February 13, 2014 at 9:00 am
I'd go a little further and get the data as time.
declare @timevar int
select @timevar = '145345'
select CAST( STUFF( STUFF( right('000000' + cast(@timevar as varchar(6)), 6), 5, 0, ':'), 3, 0, ':') AS time)
select @timevar = '23'
select CAST( STUFF( STUFF( right('000000' + cast(@timevar as varchar(6)), 6), 5, 0, ':'), 3, 0, ':') AS time)
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply