SQL Server Forums Profile | Register | Active Topics | Members | Search | Forum FAQ Register Now and get your question answered!
 All Forums  General SQL Server Forums  New to SQL Server Programming  Using a loop instead of an inner join New Topic  Reply to Topic  Printer Friendly
Author  Topic

kotonikak
Yak Posting Veteran

55 Posts

 Posted - 06/21/2012 :  15:26:52 I have the following code:with Denom as ( select a.seq, a.fx, sum(b.fx) as Denominator from DY a inner join DY b on a.seq >= b.seq group by a.seq, a.fx )which is performing the following action:seq fx Denominator1 0.01 0.012 0.01 0.023 0.01 0.034 0.01 0.045 0.01 0.05My actual data has 50,000 rows and along with this calculation, I'm performing other more complicated ones that take time. Because my data is so large and I have various calculations, this query was taking over 15 minutes to execute (more since I finally just stopped it). I was wondering if there's a way to simplify the calculation of "Denominator" by using a loop within a common table expression? Basically, start at 0 and keep adding 0.01 to my Denominator values as sequence increases. I don't know if this is going to make it faster, but I wanted to try and see since that's my only other option right now....I am also using a cross apply to calculate something else after this so that does not help with speed either... Any help will be appreciated.

jimf
Flowing Fount of Yak Knowledge

USA
2868 Posts

 Posted - 06/21/2012 :  15:32:35 Is the denominator just seq*1.0/100? JimEveryday I learn something that somebody else already knew

kotonikak
Yak Posting Veteran

55 Posts

 Posted - 06/21/2012 :  15:46:20 Yeah I guess that would seem like it. The Denominator is technically supposed to be the sum of fx up to that sequence but performing the calculation you gave me would technically give me the same results. If I have 50K rows, my denominator would then be seq/(50000)...Should of thought of that earlier..thank you!

jimf
Flowing Fount of Yak Knowledge

USA
2868 Posts

 Posted - 06/21/2012 :  17:19:27 Make sure you multiply by 1.0, if you don't you'll get nothing but 0's since and int divided by an int is an int (1/2 = 0, 3/2 = 1, etc)JImEveryday I learn something that somebody else already knew
Topic
 New Topic  Reply to Topic  Printer Friendly Jump To: Select Forum General SQL Server Forums       New to SQL Server Programming       New to SQL Server Administration       Script Library       Data Corruption Issues       Database Design and Application Architecture SQL Server 2012 Forums       Transact-SQL (2012)       SQL Server Administration (2012)       SSIS and Import/Export (2012)       Analysis Server and Reporting Services (2012)       Replication (2012)       Availability Groups and DR (2012)       Other SQL Server 2012 Topics SQL Server 2008 Forums       Transact-SQL (2008)       SQL Server Administration (2008)       SSIS and Import/Export (2008)       High Availability (2008)       Replication (2008)       Analysis Server and Reporting Services (2008)       Other SQL Server 2008 Topics SQL Server 2005 Forums       Transact-SQL (2005)       SQL Server Administration (2005)       .NET Inside SQL Server (2005)       SSIS and Import/Export (2005)       Service Broker (2005)       Replication (2005)       High Availability (2005)       Analysis Server and Reporting Services (2005)       Express Edition and Compact Edition (2005)       Other SQL Server Topics (2005) SQL Server 2000 Forums       SQL Server Development (2000)       SQL Server Administration (2000)       Import/Export (DTS) and Replication (2000)       Transact-SQL (2000)       Analysis Services (2000)       MSDE (2000) Development Tools       ASP.NET       Reporting Services Development       Other Development Tools Site Related Forums       Site Related Discussions       Article Discussion       Poll Discussion       The Yak Corral Other Forums       SQL Server 6.5 \ SQL Server 7.0       Other Topics       MS Access       ClearTrace Support Forum Old Forums       CLOSED - General SQL Server       CLOSED - SQL Server 2005/Yukon  -------------------- Home Active Topics Frequently Asked Questions Member Information Search Page
 SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC