各位好汉帮我看一下这个查询

RussellMX 2004-10-08 09:25:55
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 Function

Run-time error '-2147217900(80040e14)':
No column was specified for column 1 of 'cc'.
...全文
108 点赞 收藏 15
写回复
15 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
海洋微风 2004-10-08
为什么要嵌套呢.
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
回复
xldata 2004-10-08
当在select中select时,别名前一定要加个AS
因此CC前面应该加个AS
回复
asom 2004-10-08
语法有点错误啊,select 后面跟的不对啊,你看看楼上说的吧as ReCount from "&_
"( select count(*)'这里应该是表名啊,你这样做电脑会报错啊,FRom后面要跟表名或者视图名
回复
mingday 2004-10-08
as ReCount from 后面是表或视图名呀
回复
mingday 2004-10-08
第一个select 后的表名不对
回复
sakurako 2004-10-08
看不明白
回复
vbman2003 2004-10-08
Select Count(*) As ReCount From
(Select Count(*) As Re From t_TABLE
Where styleid=" & StyleNO & "
Group by [No]) As cc

我在SQL上试过了,没问题。你贴我的语句试试。还要注意 styleid字段是int类型
回复
fslyw 2004-10-08
没有必然这样写呀,你直接“select count(*) from t_TABLE where styleid=" & StyleNO & " group by No”这段,再看看Recordset的Count属性就可以了。
回复
of123 2004-10-08
sqlShowData = "Select Count(*) As ReCount From " & _
"(Select Count(*) As f1 From t_TABLE " & _
"Where styleid=" & StyleNO & " Group By No) cc"
回复
RussellMX 2004-10-08
这个查询原来是用于ACCESS数据库,现在用到sql server里面就不行了,sql server数据库是没有什么问题的,问题就在这个查询上面.
回复
QWERT520 2004-10-08
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
回复
RussellMX 2004-10-08
有试过加AS但是还是抱一样的错!!
也有试过将NO换成MYNO但是还是抱一样的错,这个查询是这样写的吗?请帮忙改正一下!
回复
zyg0 2004-10-08

sqlShowData = "select count(*) as ReCount from "&_
"(select count(*) from t_TABLE "&_
"where styleid=" & StyleNO & " group by [No]) cc"
no是系统的保留字
回复
boyfengliang 2004-10-08
少个As 在CC前
回复
vbman2003 2004-10-08
Select Count(*) As ReCount From
(Select Count(*) As Re From t_TABLE
Where styleid=" & StyleNO & "
Group by No) As cc
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告