I am trying to run a query in a SQL database, and for some reason I cannot use GROUP BY conditions at all, or the aggregate functions.
Changing the database itself isn't an option. There is a lot more I need to do with this, (the Command Text will end up being many many lines) but I boiled it down to this.
I've looked at several examples of how to use a GROUP BY condition, and... it seems like I am doing it right and it isn't working. Any help would be greatly appreciated, I've been working on this problem all day and can't get past it. Thanks!
Code:
Dim CLin(1 To 1) As String
CLin(1) = "select TMRA, first(TSERIALNO) from fOWSerialNo group by TMRA"
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
"ODBC;DSN=###;Description=###;UID=###;PWD=###;APP=2007 Microsoft Office system;WSID=###;DATABASE=###;Network=###" _
), Array("SOCN")), Destination:=Range("$B$1")).QueryTable
.CommandText = CLin()
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_Query_from_AQAMAN2K"
.Refresh BackgroundQuery:=False
End With
Changing the database itself isn't an option. There is a lot more I need to do with this, (the Command Text will end up being many many lines) but I boiled it down to this.
I've looked at several examples of how to use a GROUP BY condition, and... it seems like I am doing it right and it isn't working. Any help would be greatly appreciated, I've been working on this problem all day and can't get past it. Thanks!