Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ganatra.neha
Starting Member
30 Posts |
Posted - 2007-10-28 : 02:46:06
|
| I need to calcuate factorial of 2 numbers simultaneouslyMy code is as followsUse AdventureWorksGoAlter Procedure Factorial @Number decimal (38,0),@Number2 decimal (38,0),@factorial_1 decimal(38,0)output,@factorial_2 decimal(38,0)outputas Declare @tempno1 decimal (38,0)Declare @tempno2 decimal (38,0)IF @number<2 SET @factorial_1=1 ELSE BEGIN SET @tempno1 = @number-1 EXEC factorial @tempno1, @factorial_1 OUT , -- Recursive call IF (@factorial_1=-1) RETURN(-1) -- Got an error, return SET @factorial_1=@factorial_1*@numberIF (@@ERROR<>0) RETURN(-1) -- Got an error, returnENDIF @number2<2 SET @factorial_2 =1 ELSE BEGIN SET @tempno2 = @number2 -1 EXEC factorial @tempno2, @factorial_2 OUT , -- Recursive call IF (@factorial_2=-1) RETURN(-1) -- Got an error, return SET @factorial_2=@factorial_2*@number2 IF (@@ERROR<>0) RETURN(-1) -- Got an error, returnENDRETURN(0)GOI am getting follwing error Msg 156, Level 15, State 1, Procedure Factorial, Line 15Incorrect syntax near the keyword 'IF'.Msg 156, Level 15, State 1, Procedure Factorial, Line 26Incorrect syntax near the keyword 'IF'PLease anyone can let me know why i cannot execute code |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-28 : 03:07:21
|
| You've got an extra comma on the end of the line (in two places)The error says "near the keyword 'IF'" - so that's where you need to look, but such syntax errors can be either before or after the place that SQL Server detects themKristen |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
|
|
|
|
|