Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2012

    Unanswered: SQL OLE DB query result

    When I run query in excel it gives result with different column sequence. The same query gives result with different column sequence when used in query analyzer or VBA Macro. Somebody solve this mystery.

    e.g., Select * from ABC.

    result in Excel 2003 SQL OLE DB query

    col-A col-B col-C

    Result with Query Analyzer and VBA Macro

    col-c col-B col-A

  2. #2
    Join Date
    Jan 2007
    Provided Answers: 12
    And that's just another great example of why we don't use "SELECT *"!

    If you want a specific column order in your resultset then you have to list the columns out in that order
    Home | Blog

  3. #3
    Join Date
    Nov 2004
    Provided Answers: 4
    The order of the records and the order of the columns are irrelevant in a relational database. I don't know why the columns are different between those two systems, but it is irrelevant (though admittedly, it can be a nuisance).

    The general rule is :
    Only use
    SELECT * FROM MyTable
    to quickly check something in interactive mode, never use it in production code.

    You should always access the columns in an explicit way, like:
    SELECT column_A, Column_B, Column_C FROM MyTable
    in code.
    With kind regards . . . . . SQL Server 2000/2005/2012

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  4. #4
    Join Date
    Feb 2012
    Even I tried specific col. list like "Select col-C, col-B, col-A from ABC" but I always got answer in Col-A, Col-B, Col-C when query used via SQL OLE DB Query editor in Excel-2003.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts