I want to loop a table and convert into a single string. For which I used += The query goes as below.
Declare @a varchar(8000);
set @a = '';
select @a += col1+'.'+col2+' '+col3 --all are varchar columns
from table
where filter1 = <>
order by col1
I am getting only the last record from the list.
After trying so many different tweeks. Finally I used Top 1000 before the "@a +=" then the string got framed perfectly. Why am I seeing this behaviour? Note: The query has only 50 records. DB:SQL Server 14 Client: SSMS17 Thanks, Arun Kumar