Home Varchar scalar function using decimals returns only int
Reply: 1

Varchar scalar function using decimals returns only int

Vaelek
1#
Vaelek Published in 2018-02-13 17:02:18Z

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?

SMor
2#
SMor Reply to 2018-02-13 17:05:29Z

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

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.426435 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO