Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stored proc sql server
Message
From
13/10/2004 15:12:51
 
 
To
13/10/2004 14:39:57
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00950845
Message ID:
00951174
Views:
10
Have you tried splitting the last query up? I would try to do a select into a temp table (or table variable if you can get those to work <g>) of just the TOP 300. Then, using just the selected TOP 300, do the final query to combine them all. Something like:
	Select TOP 300 CustomerNumber, CustomerName, SUM(SalesAmountUSDollars) CurrentSales 
	From slsMain INTO #CurrentSales
	Where InvoiceDate >= '01/01/2004'
	Group By CustomerNumber, CustomerName
	Order By SUM(SalesAmountUSDollars) DESC

-- then do the final select

Select #CurrentSales.CustomerNumber, #CurrentSales.CustomerName, 
	#CurrentSales.CurrentSales, CurrentYearByMonth.CurrentYearMonthlySales, 
	@CurrentYearTotal AS CurrentTotalSales,  
	#TempPriorSales.PriorYearRank, #TempPriorSales.PriorSales, 
	#TempPriorSales.PriorYearMonthlySales, 
	@PriorYearTotal AS PriorTotalSales
From #CurrentSales
   LEFT OUTER JOIN 
   ( 
	Select CustomerNumber, CustomerName, SUM(SalesAmountUSDollars) CurrentYearMonthlySales
	From slsMain 
	Where InvoiceDate >= '09/01/2004'
	Group By CustomerNumber, CustomerName
   ) CurrentYearByMonth 
   ON #CurrentSales.CustomerNumber = CurrentYearByMonth.CustomerNumber and 
	#CurrentSales.CustomerName = CurrentYearByMonth.CustomerName 
   LEFT OUTER JOIN 
   	#TempPriorSales 
   ON #CurrentSales.CustomerNumber = TempPriorSales.CustomerNumber and 
	#CurrentSales.CustomerName = TempPriorSales.CustomerName 
Order By #CurrentSales.CurrentSales DESC
~~Bonnie



>each query takes a longer than 5 minutes, until i try to join the temp table with the final results. that query takes longer than 45 minutes. the error i get on the table variable is that it is not declared. like it just goes away when it gets to the final select.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform