Reputation: 2188
I'm pulling data from a Presto DB into a SQL Server table that contains a field called scan_time
, which stores time values in INT format. The values are obviously not a fixed length, so something like 1233
actually means 00:12:33
.
What is the best way to cast this as a VARCHAR, such that the value 1223
outputs as 00:12:33
?
Upvotes: 0
Views: 389
Reputation: 1269493
In SQL Server, you can convert to a time using:
select convert(time, stuff(right(concat('0', scan_time), 4), 3, 0, ':'))
Here is a db<>fiddle.
Upvotes: 1