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.
| Author |
Topic |
|
JERICHO
Starting Member
18 Posts |
Posted - 2002-09-18 : 21:05:19
|
| Hi i am having a problem with this insert into order problem. In my store procedure, i wanted to insert my values from a temp table into a physical table with a specific order let say custid. so i use the following commandsinsert into TBLa ( values...... )select values.......from #temp1order by custidbut it don't work do you have any alternative way to do it? |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2002-09-18 : 21:28:31
|
| It should work. What is it doing wrong ?Damian |
 |
|
|
JERICHO
Starting Member
18 Posts |
Posted - 2002-09-18 : 21:38:19
|
| I thought so too because i find nothing wrong with my SQL but it does don't seems to be in order and the order function is working fine sometimes and sometimes not which i suspect that it bypass the order function which i don't think is possible in SQL. Do you have a alternative? |
 |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2002-09-18 : 23:03:16
|
| Ahhh now I understand what your problem is.You need to put an order by clause on your "TBLa" table when you select from it. Using an Order By in your insert is sort of pointless as you can not control (or should now try to) how SQL Server stores data. Even if it does store it in the order you want on a physical level, it has the right to select data in the order it feels like unless you specify an order by clause in your select.If that makes sense.....Basically, don't worry about the order of your insert, do a sort in your final select.Damian |
 |
|
|
JERICHO
Starting Member
18 Posts |
Posted - 2002-09-18 : 23:15:10
|
| er..... i kinda understand what you trying to tell me but how do i put an order clause in the tblA when it is the destination tbl but not the source tbl?and i can' do final sort in select as it is in a SP and so will be display depends on the arrangment in the tbl as i am using a tool to display the database in the original order that is in the tbl. |
 |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2002-09-18 : 23:18:46
|
Then you are out of luck. Fix your display tools You can not and should not try to determine how SQL Server stores it's data. Perhaps an index on the column you wish it to be ordered by would help, but there are no guarantees.Damian |
 |
|
|
JERICHO
Starting Member
18 Posts |
Posted - 2002-09-18 : 23:28:55
|
| THANK YOU very much |
 |
|
|
|
|
|