Thursday, January 5, 2017

SQL Server -Fibonacci numbers

---Fibonacci numbers
declare @fib table(fib_id bigint,fib_val bigint)
declare @current_val bigint,@previous_val bigint,@new_val bigint
insert into @fib(fib_id,fib_val)
select top 30 row_number() over (order by name),1 from sysobjects

select @current_val=0,@previous_val=-1,@new_val=1
update @fib
set fib_val=@current_val,
@current_val=@new_val+@previous_val,
@previous_val=@new_val,
@new_val=@current_val
select * from @fib

Happy Coding!!!!!!

No comments:

Search This Blog

DAX - Grouping on multiple columns and the count

Please go thorugh the below URL for entire soultion. http://community.powerbi.com/t5/Desktop/DAX-Grouping-on-multiple-columns-and-the-cou...