Solved

Need help optimizing a pivot view

Posted on 2012-04-05
2
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

730 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