Saturday, February 6, 2010

Simple mathematical calculations using T-SQL

Logic for Different simple mathematical functions

1)Factorial for the given number

suppose i want Factorial for 10 then this is the t-sql code for printing factorial of 10


Declare @number int;
declare @num int;
set @num=1;
set @number=10;
declare @fact bigint;
set @fact=1;
while(@num<@number)
begin
select @fact=@fact*@num;
set @num=@num+1;
end
print 'the factorial of given number is '+convert(varchar(100),@fact);

No comments: