我已经浏览了该网站上的其他一些答案,但似乎没有一个与我的问题相匹配(或者至少在我眼中看起来不像!)。
我正在调整 Excel 宏,它获取客户参考列表并通过 Microsoft ODBC 在 Oracle 数据库上运行 SQL 查询。查询本身工作正常并返回正确的结果。但是,用户希望结果与原始客户参考列表的顺序相同。
因此,例如 2001145、2001101、2200110 的列表应按该顺序返回结果,而不是 2001101、2001145、2200110。
我正在寻找一种在 SQL 命令中执行此操作的方法,这可能吗?
先感谢您。
这是执行查询的代码。我不需要对输入进行排序,我需要以与输入相同(未排序)的顺序输出。
Sql = " select b.column Customer, (b.CURR_BAL + b.CURR_BAL_V) Balance"
Sql = Sql & " from table b"
Sql = Sql & " WHERE b.column = 5"
Sql = Sql & " and b.column in (" & custRefList & ")"
'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