Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Stored Procedure/View order change

Posted on 2008-10-29
8
Medium Priority
?
255 Views
Last Modified: 2012-05-05
I have a stored procedure that creates a pivot table with data from a view in SQL Sever 2000. Neither the sp or the view has changed in months. However for some reason the order in which the data is being returned from the stored procedure has just changed - this is causing huge problems as the output is copied straight to an excel spreadsheet and now its all messed up - the data is the same it is just the order of the data that has changed
Any idea what factors could influence the an order change in a sp/ view where the input data is exactly the same. Indexes is perhaps on thing that I need to look at - can u think of anything else??
0
Comment
Question by:mydo76
[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
8 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 22836113
On what columns are your data sorted?  What are those columns' data types?  What is different about
the output now vs the output in the past?
0
 

Author Comment

by:mydo76
ID: 22836700
one input parameter of the stored procedure is a list of months e.g. '200700', '200801',
'200802', '200803', '200804', '200805' and creates a pivot table where the input yyyymm list are the column names and fiills them with data. eg
'200700', '200801', '200802', '200803', '200804', '200805',
123          111          100          5000       3000        1245.1 (I have to check the type)

this is out to an excel spreadsheet - the return data from the sp should be and was in the fact in this order
'200700', '200801', '200802', '200803', '200804', '200805',
123          111          100          5000       3000        1245.1

but its coming out now as --

'200802' '200805',   '200700', '', '200803', '200804', '200801'
100          1245.1     123               5000       3000        111

ie the data is correct its just the order that is incorrect.
I need to check the colums the data is sorted on etc tomorrow
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 22837136
>>Any idea what factors could influence the an order change in a sp/ view where the input data is exactly the same. <<
The lack of an appropriate ORDER BY clause would explain it.  However without seeing the actual stored procedure, there is no tellin.
0
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 22837139
I should have also added that unless you are using an ORDER BY clause the order of the data is not guaranteed.
0
 
LVL 5

Expert Comment

by:ursangel
ID: 22841529
Yes its True that without proper order by clause, you cannot have a guarantee on the order in which the result is retrieved. SQL server has its on internal method of retrieving the records from the database. May be all these time, the order was what you ver expected, but since it has changed now, make it use ORDER BY Clause.
0
 

Author Comment

by:mydo76
ID: 22842641
I fixed this myself !! It was a problem with a temporary table - when I inserted the data to a permanent table it rectified the problem!
0
 

Accepted Solution

by:
mydo76 earned 0 total points
ID: 22842668
I should also add that I put a clustered index on the appropiate field! Thanks for all the suggestions!
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 22846525
>>I should also add that I put a clustered index on the appropiate field!<<
All you have done is mask the problem.  Until you add an ORDER BY clause you have no guarantee that the results will be returned in the same order. Period.
0

Featured Post

Technology Partners: 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

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…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

722 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