Vaelek
Vaelek

Reputation: 190

Varchar scalar function using decimals returns only int

I am banging my head on this one. If I execute this

SELECT CONVERT(varchar, CONVERT(datetime, 0.55), 108);

I get "13:12:00".

However, placing this into a scalar function as so

CREATE FUNCTION [dbo].[t_ExcelToTime] (@Excel decimal (12,8))
RETURNS varchar
AS
BEGIN
    DECLARE @Result varchar
    SELECT @Result =  CONVERT(varchar,CONVERT(datetime, @Excel), 108)
    RETURN @Result
END

And calling it as

SELECT [dbo].[t_ExcelToTime](0.55);

returns "1"

What am I doing wrong here?

Upvotes: 0

Views: 278

Answers (1)

SMor
SMor

Reputation: 2862

"returns varchar" is the same as "returns varchar(1)". Give your datatype an appropriate length.

Upvotes: 2

Related Questions