Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 3rd, 2008, 03:15 PM
Registered User
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default copy set of data to another table with order by


i have this data in the staging table called Stage1. C1,C2 and C3 are column Headers.

C1 C2 C3
41 te cc
51 te cc
42 te cc
41 te cc
51 te cc
42 te cc
41 te cc
51 te cc
42 te cc

 Now from this staging table i want to insert into another temp table in the same order but i want to insert row42 after row41. ex: 41,42,51 and again 41,42,51 and so on. If this is the case how do i query to insert into another table.

can you guys help me with the query? appreciate your help


Old August 3rd, 2008, 05:42 PM
Friend of Wrox
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts

This is the same question you asked on the other forum... the ONLY way you can come close is to put a clustered index on the target table. And, I'll say it again, RDBMS's don't store data in the order that you want. The ONLY way to guarantee correct display order is with an ORDER BY. The ONLY way to guarantee correct logical calculation order is with a clustered index and an index hint.

At least try my suggestion...
Old August 23rd, 2013, 11:21 AM
Registered User
Join Date: Nov 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql sort

dont think it makes sense

by sorting you would get
52 etc.

what youre asking for requires different values in the te cc data or an extra col.
so that really the sort order is new_field, c1

then youd get

41 newfield a te cc

42 newfield a te cc
52 newfield a te cc
41 newfield b te cc
42 newfield b te cc
52 newfield b
41 newfield c
42 newfield c
52 newfield c
you dont really need to see the new field but it must exist really for you to know theyre in the right order.

hope that helps

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding an Order to Table seananderson SQL Server 2000 1 June 28th, 2007 05:33 PM
Copy whole structure of table in #temp table maulik77 SQL Server 2000 2 December 21st, 2006 02:42 AM
How to set indexes on columns in a data table hdewees VB Databases Basics 1 June 5th, 2006 02:42 PM
copy complete data in one table to another ramanadyv SQL Language 2 March 4th, 2006 11:53 PM
copy and append records from table-A to table B bhunter Access 6 March 9th, 2004 02:02 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.