Public Function GetValue(ByVal StyleNO As Long) As Integer
    Dim rsShowData As ADODB.Recordset
    Dim sqlShowData As String
    sqlShowData = "select count(*) as ReCount from "&_
    "(  select count(*)   from t_TABLE "&_
    "where styleid=" & StyleNO & "  group by No) cc"
    Set rsShowData = GetRecordSet(sqlShowData)
    If Not rsShowData.EOF Then
        GetValue = rsShowData("Recount")
    Else
        GetValue = 0
    End If
End FunctionRun-time error '-2147217900(80040e14)':
No column was specified for column 1 of 'cc'.

解决方案 »

  1.   

    第一个select 后的表名不对
      

  2.   

    as ReCount from 后面是表或视图名呀
      

  3.   

    语法有点错误啊,select 后面跟的不对啊,你看看楼上说的吧as ReCount from "&_
        "(  select count(*)'这里应该是表名啊,你这样做电脑会报错啊,FRom后面要跟表名或者视图名
      

  4.   

    Select Count(*) As ReCount From
        (Select Count(*) As Re From t_TABLE
        Where styleid=" & StyleNO & "  
        Group by No) As cc
      

  5.   


        sqlShowData = "select count(*) as ReCount from "&_
        "(select count(*)   from t_TABLE "&_
        "where styleid=" & StyleNO & "  group by [No]) cc"
    no是系统的保留字
      

  6.   

    有试过加AS但是还是抱一样的错!!
    也有试过将NO换成MYNO但是还是抱一样的错,这个查询是这样写的吗?请帮忙改正一下!
      

  7.   

    Public Function GetValue(ByVal StyleNO As Long) As Integer
        Dim rsShowData As adodb.Recordset
        Set rsShowDate = New adodb.Recordset
        Dim sqlShowData As String
        sqlShowData = "select count(*) as ReCount from " _
                      & "(select count(*) from t_TABLE " _
                      & " where styleid=" & StyleNO & " group by No) cc"
        Set rsShowData = GetRecordSet(sqlShowData)
        If Not rsShowData.EOF Then
            GetValue = Trim(rsShowData!Recount) & vbNullString
        Else
            GetValue = 0
        End If
    End Function
      

  8.   

    这个查询原来是用于ACCESS数据库,现在用到sql server里面就不行了,sql server数据库是没有什么问题的,问题就在这个查询上面.
      

  9.   

    sqlShowData = "Select Count(*) As ReCount From " & _
        "(Select Count(*) As f1 From t_TABLE " & _
        "Where styleid=" & StyleNO & " Group By No) cc"
      

  10.   

    没有必然这样写呀,你直接“select count(*)   from t_TABLE where styleid=" & StyleNO & "  group by No”这段,再看看Recordset的Count属性就可以了。
      

  11.   

    Select Count(*) As ReCount From
        (Select Count(*) As Re From t_TABLE
         Where styleid=" & StyleNO & "  
         Group by [No]) As cc我在SQL上试过了,没问题。你贴我的语句试试。还要注意 styleid字段是int类型
      

  12.   

    当在select中select时,别名前一定要加个AS
    因此CC前面应该加个AS
      

  13.   

    为什么要嵌套呢.
    Public Function GetValue(ByVal StyleNO As Long) As Integer
        Dim rsShowData As adodb.Recordset
        Set rsShowDate = New adodb.Recordset
        Dim sqlShowData As String
        sqlShowData = "select count(*) as ReCount from t_TABLE " _
                      & " where styleid=" & StyleNO & " group by No"
        Set rsShowData = GetRecordSet(sqlShowData)
        If Not rsShowData.EOF Then
            GetValue = Trim(rsShowData!Recount) & vbNullString
        Else
            GetValue = 0
        End If
    End Function