ALTER FUNCTION [dbo].[fnConvertIntegerToTime]
(@ArrivalTime24hr int)
RETURNS varchar(12)
AS
BEGIN
DECLARE @ArrivalHour int,
@ArrivalMinute int,
@ArrivalTime varchar(12),
-- @ArrivalTime24HrChr varchar(4),
@ArrivalTime24HrLen int
SET @ArrivalTime24HrLen = LEN(@ArrivalTime24hr)
-- SET @ArrivalTime24HrChr = CAST(@ArrivalTime24hr AS varchar(2))
IF @ArrivalTime24HrLen = 0
BEGIN
SET @ArrivalHour = 00
SET @ArrivalMinute = 00
END
ELSE
IF @ArrivalTime24HrLen > 0 AND @ArrivalTime24HrLen < 3
BEGIN
SET @ArrivalHour = 00
SET @ArrivalMinute = @ArrivalTime24hr
END
ELSE
IF @ArrivalTime24HrLen = 3
BEGIN
SET @ArrivalHour = LEFT(@ArrivalTime24hr,1)
SET @ArrivalMinute = RIGHT(@ArrivalTime24hr,2)
END
ELSE
IF @ArrivalTime24HrLen = 4
BEGIN
SET @ArrivalHour = LEFT(@ArrivalTime24Hr,2)
SET @ArrivalMinute = RIGHT(@ArrivalTime24Hr,2)
END
IF @ArrivalTime24hr < 1200
BEGIN
SET @ArrivalTime = CAST(@ArrivalHour AS char(2)) + ':'+ CAST(@ArrivalMinute AS char(2)) + ':00 AM'
END
ELSE
IF @ArrivalTime24hr BETWEEN 1200 AND 1259
BEGIN
SET @ArrivalTime = CAST(@ArrivalHour AS char(2)) + ':'+ CAST(@ArrivalMinute AS char(2)) + ':00 PM'
END
ELSE
IF @ArrivalTime24hr BETWEEN 1300 AND 2359
BEGIN
SET @ArrivalTime = CAST(@ArrivalHour - 12 As char(2)) + ':'+ CAST(@ArrivalMinute AS char(2)) + ':00 PM'
END
RETURN @ArrivalTime
END
|