DECLARE @s varchar(max) DECLARE @i INT ,@max INT SET @s='' SET @i=1 SET @max=10 WHILE @i<=@max BEGIN if @i<@max SET @s=@s+'SELECT '+CONVERT(varchar(3),@i)+' UNION ALL ' else SET @s=@s+'SELECT '+CONVERT(varchar(3),@i) SET @i=@i+1 END print @s EXECUTE(@s)