Getting Started with Adobe After Effects - Part 6: Motion Blur

Upload Image Close it
Select File

Nakul Vachhrajani is a Technical Specialist & Systems development professional with iGATE. He holds a MCTS (SQL Server 2008: Implementation & Maintenance)
Browse by Tags · View All
#SQLServer 305
SQL Server 304
Administration 252
DBA 241
T-SQL 234
#TSQL 232
Development 226
Tips 216
Guidance 148
Best Practices 119

Archive · View All
April 2011 14
March 2012 11
December 2011 11
March 2011 11
December 2012 10
October 2011 10
January 2011 10
September 2013 9
January 2013 9
November 2012 9

#0338 - SQL Server - Recursive CTE - Script to generate a simple multiplication table

May 22 2014 12:00AM by Nakul Vachhrajani   

I was explaining recursive CTEs recently, and had to come up with a practical example for the CTE implementation. One of the first use cases that came to mind was the creation of a simple multiplication table. Now that the script is created, I thought that you may also find it useful sometime in the future.

USE tempdb;

--Generate basic mathematical tables using Recursive CTE
DECLARE @inputValue INT = 2;
DECLARE @targetMultiplicationFactor INT = 20;

--Define the CTE to generate a mathematical table
;WITH GenerateTablesCTE (Input, MultiplicationFactor, Result)
    --Anchor member
    SELECT @inputValue AS Input, 
            1 AS MultiplicationFactor, 
            (@inputValue * 1) AS Result
    --Recursive member
    SELECT @inputValue AS Input, 
            (gtCTE.MultiplicationFactor + 1) AS MultiplicationFactor,
            (@inputValue * (gtCTE.MultiplicationFactor + 1)) AS Result
    FROM GenerateTablesCTE AS gtCTE
    WHERE gtCTE.MultiplicationFactor < @targetMultiplicationFactor
SELECT ogtCTE.Input,
FROM GenerateTablesCTE AS ogtCTE;

Here’s the result:


This script can be used to populate a tally/look-up table.

Further Reading

  • Multiplication Table [Wikipedia Link]

Until we meet next time,

Be courteous. Drive responsibly.

Tags: #SQLServer, SQL Server, Development, T-SQL, #TSQL, Guidance, Tips

Nakul Vachhrajani
4 · 36% · 11648



  • Ooooo, be careful. Using rCTEs to count is as bad as or worse than any While loop to accomplish the same thing. They're real resource hogs, to boot. Please see the following article before you even think of using an rCTE that counts or does similar RBAR things. And, yeah... it's RBAR as you'll see in the article. link text

    commented on May 22 2014 12:58AM
    Jeff Moden
    161 · 1% · 306

Your Comment

Sign Up or Login to post a comment.

"#0338 - SQL Server - Recursive CTE - Script to generate a simple multiplication table" rated 5 out of 5 by 3 readers
#0338 - SQL Server - Recursive CTE - Script to generate a simple multiplication table , 5.0 out of 5 based on 3 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]