Row ListThis 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:
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
Is this code snippet, product or advice warrantied against ill-effect and/or technical malaise? No. No it's not! Not expressed - Not implied - not at all.