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 |
|
karthickbabu
Posting Yak Master
151 Posts |
Posted - 2008-01-08 : 06:25:09
|
| I write the Function for Factoriali use like theseIF (@FactorialFor BETWEEN 0 AND 12 )IF (@FactorialFor >= 0 AND @FactorialFor < 13 )But if i give negative value it returns 1How can handle error in functions |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-08 : 07:15:50
|
| You can use another condition to check for this likeIF (@FactorialFor < 0 )and write appreopriate code for it. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-08 : 07:36:23
|
Use this functionCreate function dbo.factorial(@n int)returns floatasbegin declare @result float set @result=1 if @n>0 begin select @result=@result*number from ( select number from master..spt_values where type='p' and number between 1 and @n ) as t end return @resultendGO and call asselect dbo.factorial(-1),dbo.factorial(6)MadhivananFailing to plan is Planning to fail |
 |
|
|
karthickbabu
Posting Yak Master
151 Posts |
Posted - 2008-01-08 : 07:43:50
|
| Sorry ya.. its simple syntax error...I solve this problem,Anyway thanks for your reply... Mr.Madhi i got some more ideas from your code |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-08 : 08:24:22
|
quote: Originally posted by karthickbabu Sorry ya.. its simple syntax error...I solve this problem,Anyway thanks for your reply... Mr.Madhi i got some more ideas from your code
Well. If you want to create a function to find factorial, then use the function I postedMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|