I written the following function.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create FUNCTION NameFunction
(
@eid int
)
RETURNS varchar
AS
BEGIN
RETURNS varchar should be RETURNS varchar(50).
varchar without a length specified is interpreted as varchar(1) in this context (and as varchar(30) in the context of a CAST).
BTW: Scalar UDFs that do data access can be performance killers. You might want to consider at least rewriting this as an inline TVF so that the optimiser has more options.