It's possible to simulate a loop in SQL Server with a self-referencing CTE and a union all, something like the following:
declare @a int = 1; declare @b int = 5; ;with Tbl as ( select @a a UNION ALL select (a + 1) a from Tbl where (a + 1) < @b ) select * from Tbl
This is useful when you want to create a list of dates from a start date to an end date and then join on those specific dates.
I could also imagine wanting to do that for columns as well. Is there a means of achieving this in SQL Server without using dynamic SQL? I would probably want to save such a query as a view, and not an SP (though I know that this could be achieved via dynamic SQL)