I am trying to make a long string from comments and I created this sp
ALTER FUNCTION ugurcode.comment_summary
(
@opinionid int
)
RETURNS nvarchar(max)
AS
BEGIN
declare @cs nvarchar(max);
select @cs+=comment+'\n' from fev_comment where opinionid=@opinionid
RETURN @cs/* value */
END
this returns null, how else can I achieve this?
Replace
with
Concatenating
NULLreturnsNULL.BTW: Microsoft say “The correct behavior for an aggregate concatenation query is undefined.” and this approach can break. You might want to look at
XML PATHinstead (See Concatenating Row Values in Transact-SQL).