1

我正在尝试从 excel 查询 vertica db,我可以很好地查询简单的 SQL 语句,但是如果我想做更复杂的查询,我会遇到麻烦。

我已经更改了我拥有的宏,但我对它们为什么将连接部分和查询部分分开感到困惑。当我将查询粘贴到 vba 模块中时,我只会收到红色文本。如果有人在查询 vertica 时有一个易于遵循的模板,将不胜感激。

我得到编译错误,期望:在我的查询as部分的查询表达式。

谢谢。

Sub stackoverflow()

    ActiveWorkbook.Worksheets.Add
     ActiveSheet.Name = "stackoverflow"
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
        "CONNECTION HERE" _
        ), Array( _
        "NEXT PART OF CONNECTION" _
        ), Array("NEXT PART OF CONNECTION")), Destination:= _
        Range("$A$1")).QueryTable
        ''.CommandType = 0
        .CommandText = Array( _
        "QUERY" _
        , _
        "QUERY CONTINUED" _
        )
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "Table NAME"
        .Refresh BackgroundQuery:=False
    End With

End Sub

包括查询部分

        Range("$A$1")).QueryTable
         ''.CommandType = 0
        .CommandText = Array( _
        "SELECT stackoverflow.date AS date,
      stackoverflow.website AS site
 FROM XXXX.Stack.stackoverflow WHERE (site = 'stackoverflow.com')"
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .ListObject.DisplayName = "Table Name"
            .Refresh BackgroundQuery:=False
        End With
4

0 回答 0