CREATE FUNCTION Tick (
@px MONEY
) RETURNS VARCHAR(20) AS BEGIN
DECLARE @result VARCHAR(20)
DECLARE @intTicks INTEGER
DECLARE @strTicks VARCHAR(10)
DECLARE @intHandl INTEGER
DECLARE @intEights INTEGER
DECLARE @intSign INTEGER
SET @intSign = CASE WHEN @px < 0 THEN -1 ELSE 1 END
SET @px = ABS(@px)
SET @intHandl = FLOOR(@px)
SET @intTicks = (@Px - @intHandl) * 32
SET @intEights = CAST((((@Px - @intHandl) * 32 - @intTicks) * 8) AS INTEGER)
SET @intHandl = @intHandl * @intSign
SET @strTicks = RIGHT('00' + CAST(@intTicks AS VARCHAR(10)), 2)
SET @result = CAST(@intHandl AS VARCHAR(10)) + '-' + @strTicks + ':' + CAST(@intEights AS VARCHAR(10))
RETURN CASE WHEN @intSign < 0 THEN '-' ELSE '' END + @result
END
|