Even if you manage to get this to work in a function, your statement RETURNS varchar
will result in the result being implicitly converted to varchar(1)
in the output.
I assume this is related to your previous question, in which case this may work better for you.
ALTER FUNCTION FixMe(@colvalue VARCHAR(8000),
@width INTEGER)
RETURNS VARCHAR(8000)
WITH SCHEMABINDING, RETURNS NULL ON NULL INPUT
AS
BEGIN
RETURN REPLACE(RTRIM(@colvalue), ' ', ' ') +
CASE
WHEN @width > LEN(@colvalue)
THEN REPLICATE(' ', @width - LEN(@colvalue))
ELSE ''
END
END
source
share