March 11, 2005 at 3:26 pm
I'm having a problem concatenating a variable to itself. I don't receive an error, I just don't receive any results. Below is the code I'm using.
--First I tried setting the value in a select statement and didn't receive any results
DECLARE @To nvarchar(1000)
SELECT @To = @To + email + ';'
FROM tblNotifications
WHERE NotifyType = 1 AND EmailNotify = 1
PRINT @To
--So I tried it with a cursor and received the same result
DECLARE @email nvarchar(20), @To nvarchar(1000)
DECLARE email_notify CURSOR FOR
SELECT email
FROM tblNotifications
WHERE NotifyType = 1 AND EmailNotify = 1
OPEN email_notify
FETCH NEXT FROM email_notify INTO @email
WHILE @@FETCH_STATUS = 0
BEGIN
SET @To = @To + @email + ';'
FETCH NEXT FROM email_notify INTO @email
END
CLOSE email_notify
DEALLOCATE email_notify
PRINT @To
March 11, 2005 at 3:29 pm
You aren't initializing @To.
That means it is NULL.
NULL concatenated with anything is always NULL
DECLARE @To nvarchar(1000)
SELECT @To = '' -- Initialize to empty string
March 11, 2005 at 3:37 pm
You really are a veteran. I've never run into that problem before but it makes sense. Thanks for the help!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply