The code below is doing just what i want it to do, as far as converting the time to a format that works for my needs. However, when the minutes and seconds are in the single digit, the format is not looking good. I would like to adjust the code to pad the minutes and seconds where it is needed. Any suggestions? Again, i would like to stay with the existing code as much as possible.
Thank you!
SELECT SUBSTRING(CONVERT(CHAR(14), DateTimeRaw, 100), 13, 2) + ':' +
CONVERT(nvarchar, DATEPART(minute, DateTimeRaw)) + ':' +
CONVERT(nvarchar, DATEPART(second,
DateTimeRaw)) + '.' + CONVERT(nvarchar, DATEPART(ms, DateTimeRaw) / 100)
+ ' ' + CONVERT(nvarchar, CASE WHEN datepart(hour, DateTimeRaw)
< 12 THEN 'AM' ELSE 'PM' END) AS AGMPLUSMSTIME
FROM RAW