try this
DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+',' ,'') + Cast(empid as varchar(10))
FROM table1
SELECT @listStr
Here empid is my integer column
and table1 is my table
For your scenario, try this
declare @count as int=1
DECLARE @listStr VARCHAR(MAX)
while @count<=20
BEGIN
SELECT @listStr = COALESCE(@listStr+',' ,'') + Cast(SQUARE(@count) as varchar(10))
set @count=@count+1
END
select @listStr
output:
1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400