I have a table with column email
. I need to return all those emails in a string. I'm trying this code but getting:
Msg 102, Level 15, State 1, Procedure getemailjcp, Line 24
Incorrect syntax near '='.
Msg 102, Level 15, State 1, Procedure getemailjcp, Line 31
Incorrect syntax near 'a'.
TSQL function:
ALTER function [dbo].[getemails]
(
@DB_Name varchar(100)
)
Returns varchar(4000)
AS
BEGIN
DECLARE @out varchar (4000);
DECLARE @in varchar (4000);
SET @out =
(
SELECT @in = @in + email +'; '
FROM
(
SELECT DISTINCT ISNULL(U.nvarchar4, 'NA') as email
FROM
sometable
) a
) b
RETURN @out
END