Set based, with no loopdeclare @x varchar(40)declare @FromValue intdeclare @ToValue intselect @FromValue = 6, @ToValue = 14select @x = isnull(@x+', ','')+ convert(varchar(20),number)from ( select top 100 percent number from -- Function from script library F_TABLE_NUMBER_RANGE(@FromValue,@ToValue) order by number ) aselect x= @x
Results:x ---------------------------------------- 6, 7, 8, 9, 10, 11, 12, 13, 14(1 row(s) affected)
CODO ERGO SUM