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
Solved

Need help optimizing a pivot view

Posted on 2012-04-05
2
276 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

856 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