Retrieving rows w/ BCP in order

  • Hi,

    I want to retrieve rows from a database table in the order in which they were inserted into the database.  By default, BCP is sorting in alphabetical order.  Any ideas on how I can do this without SQL voodoo or identify fields?

  • Not sure if I understand correct, but why don't you use a query with an ORDER BY according to your columns?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • It's like this.  When you open up SQL Server and view all rows, it returns the results in what looks like the order in which they hit the database, by default.  I was told that unlike Oracle, SQL Server doesn't keep any hidden identifiers.  I was just curious about how SQL Server does its default sorting, really. =)

  • When the table is a heap, I think the order is quite random. When the table has a clustered index, I believe this to be in order of the clustered index. Anyway, you shouldn't rely only on this. That's why I meant, use an ORDER BY, as this is the only reliable way to get the sorted result you expect.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply