<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>You REQUIRE a Numbers table!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx</link><description>Looking at my list of upcoming articles, I keep seeing the same theme repeated over and over. A sequence table of Numbers. Numbers tables are truly invaluable. I use them all of the time for string manipulation, simulating window functions, populating</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx#11435</link><pubDate>Sun, 25 Jan 2009 19:44:15 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11435</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;There are many techniques for splitting a string in T-SQL (in other words, taking a character-delimited&lt;/p&gt;
</description></item><item><title>Counting occurrences of a substring within a string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx#11436</link><pubDate>Sun, 25 Jan 2009 19:44:50 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11436</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;I have absolutely no idea why anyone wants to do this, but I keep answering the same question in forums:&lt;/p&gt;
</description></item><item><title>Dealing with very large bitmasks</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx#11437</link><pubDate>Sun, 25 Jan 2009 19:45:35 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11437</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Continuing in my series of things you should probably not do in SQL Server but sometimes have to , I'm&lt;/p&gt;
</description></item><item><title>"Reflect" a TSQL routine</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx#11445</link><pubDate>Sun, 25 Jan 2009 19:53:28 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11445</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Ever want to see the text of a stored procedure, function, or trigger -- or manipulate the text in some&lt;/p&gt;
</description></item><item><title>Tokenize UDF</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx#11447</link><pubDate>Sun, 25 Jan 2009 19:54:26 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11447</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Yes, another string splitting UDF from a guy who's obvioiusly become obsessed with TSQL string splitting.&lt;/p&gt;
</description></item><item><title>re: You REQUIRE a Numbers table!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx#31144</link><pubDate>Tue, 30 Nov 2010 01:00:05 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:31144</guid><dc:creator>Chen Noam</dc:creator><description>&lt;p&gt;Great article, very good performance.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Chen&lt;/p&gt;
</description></item><item><title>re: You REQUIRE a Numbers table!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx#38996</link><pubDate>Tue, 11 Oct 2011 17:13:36 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38996</guid><dc:creator>Joel Theophanes</dc:creator><description>&lt;p&gt;Another number table generator. Not as compact as Adam's, but easy to see how many numbers are generated and doesn't rely on a system table for the initial number list.&lt;/p&gt;
&lt;p&gt;;with t as (&lt;/p&gt;
&lt;p&gt;	select 0 as Num union&lt;/p&gt;
&lt;p&gt;	select 1 union&lt;/p&gt;
&lt;p&gt;	select 2 union&lt;/p&gt;
&lt;p&gt;	select 3 union&lt;/p&gt;
&lt;p&gt;	select 4 union&lt;/p&gt;
&lt;p&gt;	select 5 union&lt;/p&gt;
&lt;p&gt;	select 6 union&lt;/p&gt;
&lt;p&gt;	select 7 union&lt;/p&gt;
&lt;p&gt;	select 8 union&lt;/p&gt;
&lt;p&gt;	select 9&lt;/p&gt;
&lt;p&gt;)&lt;/p&gt;
&lt;p&gt;select (10000 * t10000.Num) + (1000 * t1000.Num) + (100 * t100.Num) + (10 * t10.Num) + t1.Num as Number&lt;/p&gt;
&lt;p&gt;from t t1&lt;/p&gt;
&lt;p&gt;	cross join t t10&lt;/p&gt;
&lt;p&gt;	cross join t t100&lt;/p&gt;
&lt;p&gt;	cross join t t1000&lt;/p&gt;
&lt;p&gt;	cross join t t10000&lt;/p&gt;
&lt;p&gt;order by Number&lt;/p&gt;
</description></item><item><title>re: You REQUIRE a Numbers table!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx#39086</link><pubDate>Mon, 17 Oct 2011 01:50:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:39086</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Nice, Joel. I use the following technique these days, which I learned a while back from Itzik Ben-Gan:&lt;/p&gt;
&lt;p&gt;---&lt;/p&gt;
&lt;p&gt;DECLARE @number_of_numbers INT = 100000;&lt;/p&gt;
&lt;p&gt;;WITH&lt;/p&gt;
&lt;p&gt;a AS (SELECT 1 AS i UNION ALL SELECT 1),&lt;/p&gt;
&lt;p&gt;b AS (SELECT 1 AS i FROM a AS x, a AS y),&lt;/p&gt;
&lt;p&gt;c AS (SELECT 1 AS i FROM b AS x, b AS y),&lt;/p&gt;
&lt;p&gt;d AS (SELECT 1 AS i FROM c AS x, c AS y),&lt;/p&gt;
&lt;p&gt;e AS (SELECT 1 AS i FROM d AS x, d AS y),&lt;/p&gt;
&lt;p&gt;f AS (SELECT 1 AS i FROM e AS x, e AS y),&lt;/p&gt;
&lt;p&gt;numbers AS &lt;/p&gt;
&lt;p&gt;(&lt;/p&gt;
&lt;p&gt;	SELECT TOP(@number_of_numbers)&lt;/p&gt;
&lt;p&gt;		ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS number&lt;/p&gt;
&lt;p&gt;	FROM f&lt;/p&gt;
&lt;p&gt;)&lt;/p&gt;
&lt;p&gt;SELECT *&lt;/p&gt;
&lt;p&gt;FROM numbers&lt;/p&gt;
&lt;p&gt;---&lt;/p&gt;
</description></item><item><title>re: You REQUIRE a Numbers table!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx#47208</link><pubDate>Thu, 17 Jan 2013 22:34:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47208</guid><dc:creator>joining to a numbers table</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I'd like to joint to a numbers table using the row_number value. &amp;nbsp;WITHOUT using a CTE. &amp;nbsp;I'm interested to see if it's faster and possible without CTE. &amp;nbsp;I can't think of a way to join the ROW_NEMBER Value to the Number table.&lt;/p&gt;
&lt;p&gt;Thanks for reading.&lt;/p&gt;
</description></item><item><title>re: You REQUIRE a Numbers table!</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/you-require-a-numbers-table.aspx#47224</link><pubDate>Sat, 19 Jan 2013 21:10:22 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47224</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Sure, you can do it without a CTE. Use a derived table.&lt;/p&gt;
&lt;p&gt;--Adam&lt;/p&gt;
</description></item></channel></rss>