SQL:选择*不支持-从子查询中获取列名

时间:2020-01-09 17:20:05

标签: sql db2

Showcase是我使用的平台的供应商,它由位于我们的DB2 DB中间层之上的Showcase服务器组成,以减少DB2本身的性能影响。 Showcase Query是他们的客户端应用程序和查询界面。它不支持Select *,并且我有数百个依赖*的测试。 希望改为使用子查询:

Select (select COLUMN_NAME from sysibm.columns where TABLE_NAME='sometable')
From 'sometable'

这将返回"Result of SELECT more than one row"。我需要针对不同宽度的表重用此代码,所以我不想通过索引指定列,将不胜感激。

1 个答案:

答案 0 :(得分:-1)

选择时,必须为所有列(在每个DB AFAIK中)指定列名或*。

这可能会为除最简单的表以外的所有表生成一个以上的行错误。因为某个表中有不止一列。

Sub PastingNextPage()
  Dim sh As Worksheet, sh1 As Worksheet, arrIn As Variant, arrOut() As Variant
  Dim lastRowIn As Long, lastRowOut As Long, nonEmpt As Long, rngP As Range, nrEl As Long
  Dim i As Long, j As Long, P As Long

  Set sh = Sheets("DATA"): lastRowIn = sh.Range("P" & sh.Rows.count).End(xlUp).Row
  Set sh1 = Sheets("Sheet2"): lastRowOut = sh1.Range("A" & sh1.Rows.count).End(xlUp).Row + 1

  arrIn = sh.Range("G2:Z" & lastRowIn).Value

  nrEl = lastRowIn - Application.WorksheetFunction.CountIf(sh.Range("P2:P" & lastRowIn), "") - 2
    P = 10 'column P:P number in the range starting with G:G column
    ReDim arrOut(nrEl, 3) 'redim the array to keep the collected values
    For i = 1 To lastRowIn - 1
        If arrIn(i, P) <> "" Then
            arrOut(j, 0) = arrIn(i, 1): arrOut(j, 1) = arrIn(i, P): arrOut(j, 2) = arrIn(i, 20)
            j = j + 1
        End If
    Next i

    sh1.Range(sh1.Cells(lastRowOut, "A"), sh1.Cells(lastRowOut + nrEl, "C")).Value = arrOut
End Sub

要解决此问题,您必须在where子句中添加更多条件

select COLUMN_NAME from sysibm.columns where TABLE_NAME='sometable'