C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » SQL »

Recursion in SQL


Posted Date: 06 Aug 2009    Resource Type: Code Snippets    Category: SQL
Author: Shunmuganathan MMember Level: Diamond    
Rating: 1 out of 5Points: 10




We can write the Stored Procedure for calculating the Recursion

Following is the code for Calculating the Recursion

CREATE PROC sp_Factorial
@InPara int,
@OutPara int OUTPUT
AS
DECLARE @InCalc int
DECLARE @OutCalc int
IF @InPara != 1
BEGIN
SELECT @InCalc = @InPara - 1

EXEC sp_Factorial @InCalc, @OutCalc OUTPUT

SELECT @OutPara = @InPara * @OutCalc
END
ELSE
BEGIN
SELECT @OutPara = 1
END
RETURN
GO

Following is the code to execute the SP "sp_Factorial"

DECLARE @CalcOut int
DECLARE @CalcIn int
SELECT @CalcIn = 6
EXEC sp_Factorial @CalcIn, @CalcOut OUTPUT

PRINT ' factorial of ' + CAST(@CalcIn AS varchar) + 'is ' + CAST(@CalcOut AS varchar)
GO



By
Nathan



Responses

Author: Prashant Mishra    17 Sep 2009Member Level: Bronze   Points : 0
Nice Code! Add some more similor resources


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Recursion in SQL  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Nested subquery
Previous Resource: Insert bulk amount of data
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use