Solved

Need help optimizing a pivot view

Posted on 2012-04-05
2
273 Views
Last Modified: 2012-04-05
Hello,

I have the following view that's taking 40 seconds to execute.  I've been trying to speed it up and am having no lock.  I am using MS SQL server 2005

SELECT p1.USI,
      MAX([Review1]) AS [Review1],    
      MAX([Review2]) AS [Review2],  
      MAX([Review3]) AS [Review3],  
      MAX([Review4]) AS [Review4],
      MAX([Review5]) AS [Review5],    
      MAX([Review6]) AS [Review6],  
      MAX([Review7]) AS [Review7],  
      MAX([Review8]) AS [Review8]
FROM (
SELECT      USI, Review, 'Review'+CONVERT(VARCHAR(2),rn) ReviewPvtCol            
FROM      (SELECT USI, Review,             
                  ROW_NUMBER() OVER (PARTITION BY USI ORDER BY Review) rn
             FROM  dbo.vwViewAllForPivot) AS SourceTable
) p
PIVOT
(
max(Review)
FOR ReviewPvtCol IN ([Review1], [Review2], [Review3], [Review4], [Review5], [Review6], [Review7], [Review8])
) AS P1

GROUP BY P1.USI
GO
0
Comment
Question by:chtullu135
2 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37812922
How many rows does dbo.vwViewAllForPivot have?
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 37813201
*Again*, this may just be "What it is"...

This is basically the same Q as this one:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_27661444.html
If not, then please explain the difference...?
...otherwise this issue need to be addressed in the original question...

Make sense?

JeffCoachman
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now