Note that there are some explanatory texts on larger screens.

plurals
  1. POOutput from SQL query needs to be in the same order as the input
    primarykey
    data
    text
    <p>I've taken a look through some of the other answers on the site for this one, but none seem to match my problem (or at least don't look like it to my eyes!).</p> <p>I'm adjusting an Excel macro, it takes a list of customer references and runs a SQL Query via Microsoft ODBC on the Oracle database. The query itself works fine and returns the correct results. However the user wants the results to be in the same order as the original list of customer references.</p> <p>So for example a list of 2001145, 2001101, 2200110 should return the results in that order instead of 2001101, 2001145, 2200110.</p> <p>I'm looking for a way to do this in the SQL command, is this possible?</p> <p>Thank you in advance.</p> <hr> <p>Here is the code to do the query. I don't need to sort the input, I need the output in the same (unsorted) order as the input.</p> <pre><code>Sql = " select b.column Customer, (b.CURR_BAL + b.CURR_BAL_V) Balance" Sql = Sql &amp; " from table b" Sql = Sql &amp; " WHERE b.column = 5" Sql = Sql &amp; " and b.column in (" &amp; custRefList &amp; ")" 'Runs the SQL Query, result applied to the destination 'Don't need to worry about any other settings exceot the UID,PRD and SERVER depending on system (same as toad) With ActiveSheet.QueryTables.Add(Connection:= _ "ODBC;DRIVER={Microsoft ODBC for Oracle};UID=*****;PWD=*****;SERVER=*****;" _ , Destination:=Range("A1")) .CommandText = (Sql) .Name = "Query from *****" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = True .SaveData = True .AdjustColumnWidth = False .RefreshPeriod = 0 .PreserveColumnInfo = True .Refresh BackgroundQuery:=False End With </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload