Reputation: 7201
Please see my code below, I want to convert the SmsStartTime to a time.
So result below needs to be 16:00:00.0000000
DECLARE @SmsStartTime AS VARCHAR(2) = 16
--SELECT @SmsStartTime
SELECT CAST(@SmsStartTime AS TIME)
And result below needs to be 05:00:00.0000000
DECLARE @SmsStartTime AS VARCHAR(2) = 5
--SELECT @SmsStartTime
SELECT CAST(@SmsStartTime AS TIME)
Upvotes: 0
Views: 2867
Reputation: 6656
You can try this -
DECLARE @SmsStartTime AS VARCHAR(2) = 16
SELECT CAST(@SmsStartTime + ':00:00' AS TIME)
Result
16:00:00.0000000
Upvotes: 1
Reputation: 1864
Try this (if you have SQL Server 2012):
DECLARE @SmsStartTime AS VARCHAR(2) = 5
SELECT TIMEFROMPARTS(@SmsStartTime,0,0,0,7)
https://msdn.microsoft.com/en-us/library/hh213398.aspx
Upvotes: 4