Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Copying results to a temp table

Author  Topic 

orozcoc
Starting Member

13 Posts

Posted - 2002-09-20 : 16:49:10
When copying ORDERED results into a temp table, I found out that the temp table is not totally in order. It seems that SQL Server first looks for some ordered rows and when it hits the end of the table it jumps back to the beginning and begins to report those records in order until it hits the starting place of the whole query.

Is this normal ?



robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-09-20 : 16:56:58
Have you seen this?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=19877

Adding a clustered index to your temp table might fix it.

Don't forget, unless you use an ORDER BY in your SELECT statement (not SELECT...INTO) you can't make any assumptions about the order of the rows returned.

Go to Top of Page

orozcoc
Starting Member

13 Posts

Posted - 2002-09-21 : 22:58:49
I fixed it by putting an UDF in between my SP and the source view. By doing this I was able to put a parameter in the view and therefore everything was inserted in-order. The problem was the way SQL server was scanning the view and the way your cross-tab script has to group the result set.

Thanks a lot for all your help and ideas, you guys really rock on this, now I have a rock solid script that performs really well < 1 second for a really big set, plus I'm not using cursors anymore and the ASPX UI receives only a subset (page) of the real data and therefore reducing the page rendering to less than 2 seconds.

Go to Top of Page
   

- Advertisement -