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 2012 Forums
 Other SQL Server 2012 Topics
 Sort/output

Author  Topic 

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2012-08-15 : 11:59:53

okay,so kinda odd. i used to do this all the time in 2008, but now it wont work.

if i take a table, and sort it into another table, it doesnt sort.

i.e:
this works fine (as far as what's displayed:
select * from append.dbo.[01001] order by zip10


but when i drop it into a table to export it, it's no longer sorted.
select * into append.dbo.[01001_sorted] from append.dbo.[01001] order by zip10

select * from append.dbo.[01001_sorted]


any ideas?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-15 : 12:28:03
you cant guarantee order of retrieval unless you use order by in select

so you need to use like

select * from append.dbo.[01001_sorted] order by zip10


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2012-08-15 : 12:33:20
anything else i can do? issue is that after the select .. into, i usually call an export script. i'd rather not have to add another parameter on the proc for sorting.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-15 : 13:03:43
quote:
Originally posted by albertkohl

anything else i can do? issue is that after the select .. into, i usually call an export script. i'd rather not have to add another parameter on the proc for sorting.


why do you need to parameterise sorting? isnt it always based on same field?


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2012-08-16 : 00:14:31
nope. :( my export script basically will dynamically generate a layout, and then dump via bcp with "," formatting and a header.

i export all kinds of fields/columns/formats, this was just one example.
Go to Top of Page
   

- Advertisement -