我有一个带有 column 的表email
。我需要以字符串形式返回所有这些电子邮件。我正在尝试这段代码,但得到:
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 函数:
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