## T-SQL Arithmetic and Geometric Sequence (Series)

 Author Message steve.jacobs Ten Centuries Group: General Forum Members Points: 1076 Visits: 279 Comments posted to this topic are about the item T-SQL Arithmetic and Geometric Sequence (Series) sneumersky SSCarpal Tunnel Group: General Forum Members Points: 4376 Visits: 487 Somewhere your algebra 2 teacher is smiling......I wonder what the performance difference would be if these operations were done in the CLR vs T-SQL:a. In 2008b. In 2008 R2c. In 2012d. In 2014Would the difference be way less if the T-SQL operation was performed by natively compiled stored procedures accessing an in-memory table? steve.jacobs Ten Centuries Group: General Forum Members Points: 1076 Visits: 279 sneumersky (12/14/2013)Somewhere your algebra 2 teacher is smiling......I wonder what the performance difference would be if these operations were done in the CLR vs T-SQL:a. In 2008b. In 2008 R2c. In 2012d. In 2014Would the difference be way less if the T-SQL operation was performed by natively compiled stored procedures accessing an in-memory table?Algebra 2? Actually we covered these formulas in 2nd grade :-P. As for the performance difference, it is faster (at least 50% (taking in to account memory, processors, etc.) in the CLR because of the compiled code. But here is a really good article and test scenario comparing T-SQL UDF vs. SQLCLR UDF. While the article focuses on splitting strings, it applies for any UDF process. By the way, we use Idera for all of our database (scripts included) performance measurements. http://blog.idera.com/sql-server/performance-and-monitoring/comparing-simple-efficiencies-t-sql-udf-vs-sqclr-udf-for-splitting-strings/ Just as an FYI, this was asked of me years ago for some students in the 3rd grade. Basically, all the formulas were in UDF's (so the code was "clean") and had a ASP.NET front-end. Other UDF formulas I added were Arithmetic Series Summing, Geometric Series Summing and Mathematical Series.Anyway, I wanted to share an easy and fun QoTD. thava Right there with Babe Group: General Forum Members Points: 765 Visits: 558 To be honest, it's too much of calculation, To me finding a geometric sequence with bare hands is not that much easier, when it reach over 10th term it's going to a night mare,so i just find the answer for arithmetic and tick it straight away, if there are more than two same answers for the arithmetic mean i would surely get stuck, seems bit lucky today? i got the answer Right Every rule in a world of bits and bytes, can be bend or eventually be brokenMyBlog About Common dialog controlA Visualizer for viewing SqlCommand object script Hany Helmy SSCertifiable Group: General Forum Members Points: 5983 Visits: 1119 As per the question, it was mentioned that "Developed and tested using SQL Server 2008 R2 SP2"; so why don`t we use the new features available from SQL Server 2008 onwards like follows:`declare @start float = 1, @commonDiff float = 3, @counter float = 0print 'Begin';while @counter < 200 begin set @counter += 1 declare @currVal float = 0`Setting the Variable`s values in the same declaration is more efficient, easier, faster and it looks even better.BTY; I tested it, got the same results. Søren SSC-Enthusiastic Group: General Forum Members Points: 194 Visits: 189 a ) is missing in the line (at the end).Then Ceiling((@start + (@commonDiff * (@counter -1))) * Power(10,1))/Power(10, 1Otherwise a very nice example :-) Søren, MCITP SQL 2008 (administration / programming), MCITP SQL 2005 (BI), MCT Koen Verbeeck SSC Guru Group: General Forum Members Points: 111885 Visits: 13338 Whoah whoah, it's Monday! Easy with the questions :-D(seriously, nice question) How to post forum questions.Need an answer? No, you need a question.What’s the deal with Excel & SSIS?My blog at SQLKover.MCSE Business Intelligence - Microsoft Data Platform MVP Toreador SSCertifiable Group: General Forum Members Points: 5014 Visits: 8188 Søren (12/16/2013)a ) is missing in the line (at the end).I'm most disappointed that there aren't already several pages of identical posts moaning about that and demanding that some points be given back ;-)I confess to getting it right by the same method as thava used - check the easy bit and ignore the hard bit! Søren SSC-Enthusiastic Group: General Forum Members Points: 194 Visits: 189 It is not about getting points back or focusing on wrong things. It is a good, funny and very interesting example and why not make it better by fixing the code? Søren, MCITP SQL 2008 (administration / programming), MCITP SQL 2005 (BI), MCT free_mascot SSChampion Group: General Forum Members Points: 12137 Visits: 2250 Bit complicated. ---------------------------------------------------"Thare are only 10 types of people in the world:Those who understand binary, and those who don't."