SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Other SQL Server 2012 Topics
 Sort/output
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

albertkohl
Aged Yak Warrior

USA
740 Posts

Posted - 08/15/2012 :  11:59:53  Show Profile  Visit albertkohl's Homepage  Reply with Quote

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

India
52325 Posts

Posted - 08/15/2012 :  12:28:03  Show Profile  Reply with Quote
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

USA
740 Posts

Posted - 08/15/2012 :  12:33:20  Show Profile  Visit albertkohl's Homepage  Reply with Quote
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

India
52325 Posts

Posted - 08/15/2012 :  13:03:43  Show Profile  Reply with Quote
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

USA
740 Posts

Posted - 08/16/2012 :  00:14:31  Show Profile  Visit albertkohl's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000