I have the code below and I want to loop through a table and set a variable that can then be used to updated a field in another table, but the variable keeps showing as NULL when I try to read it. What am I doing wrong?
declare @CustId nchar(15)
declare @CustID1 nchar(255)
declare @DateTime1 nchar(25)
declare @finalnote varchar(max)
declare @RowNum int
declare CustList cursor for
select
DateTime, Username, Notes
from tbl_DesignNotes
where OrderNumber = 10645
order by ID
OPEN CustList
FETCH NEXT FROM CustList INTO @DateTime1, @CustId, @CustID1
set @RowNum = 0
WHILE @@FETCH_STATUS = 0
BEGIN
set @RowNum = @RowNum + 1
set @finalnote = @finalnote + ' ' + @DateTime1 + ' ' + @CustId + ' ' + @CustID1;
--select @finalnote
--print @finalnote
select @finalnote as varText;
--print @DateTime1 + ' ' + @CustId + ' ' + @CustID1
FETCH NEXT FROM CustList INTO @DateTime1, @CustId, @CustID1
END
CLOSE CustList
DEALLOCATE CustList