I have a scalar value function that returns a VarChar(MAX)
In my stored procedure I do this
declare @p_emailAddr varchar(MAX) = (select db.dbo.GetEmails(10))
If I do print @p_emailAddr
it shows me it was populated with the correct information but the rest of the code doesn't work correctly using it. (I have no clue why, it doesn't make sense!)
Now if I change it like this
declare @p_emailAddr varchar(MAX) = 'test@email.com;'
The rest of my code works perfect as it should!
What is the difference between the two methods of setting @p_emailAddr
that is breaking it?
This is get emails code
ALTER FUNCTION [dbo].[GetEmails](@p_SubID int)
RETURNS varchar(max)
AS
BEGIN
DECLARE @p_Emails varchar(max)
SELECT @p_Emails = COALESCE(@p_Emails + ';', '') + E.EmailAddress
FROM db.dbo.UserEmailAddr E JOIN
db.dbo.EmailSubscriptionUsers S on e.ClockNumber = s.Clock AND S.SubID = @p_SubID
SET @p_Emails = @p_Emails + ';'
RETURN @p_Emails
END