Home
  Home
Home
Search
Articles
Page Tag-Cloud
  Software
Software Tag-Cloud
Building from Source
Open Source Definition
All Software
  Popular Tags
C Plus Plus
Source Code
Legacy
Class
Networking
  Members
Login
Web-Email
Notable Members
  Official
Our Company
Copyright Information
Software EULA
GPL EULA
LGPL Eula
Pre-Release EULA
Privacy Policy
  Support
Make Contact
 
 
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:
1
2
3
...
98
99
100


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.



Tags:
 Function    Rowset    Snippet    SQL Server  

Created by Josh Patterson on 2/9/2013, last modified by Josh Patterson on 2/9/2013

No comments currently exists for this page. Why don't you add one?
First Previous Next Last 

 
Copyright © 2024 NetworkDLS.
All rights reserved.
 
Privacy Policy | Our Company | Contact