Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 3rd, 2008, 03:15 PM
Registered User
 
Join Date: Dec 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default copy set of data to another table with order by

Hi,

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

Thx


Reply With Quote
  #2 (permalink)  
Old August 3rd, 2008, 05:42 PM
Friend of Wrox
Points: 1,533, Level: 15
Points: 1,533, Level: 15 Points: 1,533, Level: 15 Points: 1,533, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 474
Thanks: 0
Thanked 9 Times in 9 Posts
Default

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...
Reply With Quote
  #3 (permalink)  
Old August 23rd, 2013, 11:21 AM
Registered User
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Location: england
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql sort

dont think it makes sense

by sorting you would get
41
41
41
42
42
42
52
52
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
etc
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01: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 10:53 PM
copy and append records from table-A to table B bhunter Access 6 March 9th, 2004 01:02 PM



All times are GMT -4. The time now is 09:55 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.