Row List

This table valued function returns a table with a defined number of rows. I've used it in the past to create a cartesian product for test data generation - but I'm sire there is a better use somewhere.

Example: SELECT * FROM dbo.RowList(100, 1)

Returns:

Id
1
2
3
...
98
99
100

tSQL

CREATE FUNCTION RowList(@Rows INT, @Step INT = 1)
RETURNS @RowList TABLE (Row INT)  AS
BEGIN
-- Fill the table variable with the rows for your result set
	DECLARE @Count INT

	WHILE(IsNull(@Count, 0) < IsNull(@Rows, 1))
	BEGIN
		INSERT @RowList(Row) VALUES((IsNull(@Count, 0) + IsNull(@Step, 1)))
		SET @Count = (IsNull(@Count, 0) + IsNull(@Step, 1))   
	END     
RETURN 
END