以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  sql  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=149519)

--  作者:yetle
--  发布时间:2020/5/5 10:00:00
--  sql
sql代码里面加了And  " & Filter & " 后提示列名 \'_identify\' 无效,不加的话正常显示。

请问老师什么原因,怎么改?

Dim xl As WinForm.ComboBox = e.Form.Controls("系列")
Dim wgh As WinForm.ComboBox = e.Form.Controls("物供号")


Dim dt1 As WinForm.DateTimePicker = e.Form.Controls("开始日期")
Dim dt2 As WinForm.DateTimePicker = e.Form.Controls("结束日期")


Dim filter As String = "  _identify>0 "

If  xl.Text > "" Then
    filter= filter & " and 系列 =  \'" & xl.Text & "\'"
End If

If  wgh.Text > "" Then
    filter= filter & " And 物供号 =  \'" & wgh.Text & "\'"
End If


If  dt1.Text > "" Then
    filter= filter & " And 货期 >= \'" & dt1.Text & "\'"
End If

If  dt2.Text > "" Then
    filter= filter & " And 货期 <= \'" & dt2.Text & "\'"
End If

Dim t1 As WinForm.Table = e.Form.Controls("Table1")
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = 

dt = cmd.ExecuteReader()
t1.Table.DataSource  =dt


[此贴子已经被作者于2020/5/5 16:48:03编辑过]

--  作者:有点蓝
--  发布时间:2020/5/5 10:08:00
--  
Dim filter As String = "  [_identify] >0 "

identify这个名字和数据库的关键字有冲突,需要加上中括号

--  作者:yetle
--  发布时间:2020/5/5 11:45:00
--  
加上去还是一样提示
--  作者:有点蓝
--  发布时间:2020/5/5 11:52:00
--  
说明当前表没有_identify这个列
--  作者:yetle
--  发布时间:2020/5/5 14:59:00
--  
是的,是这个问题,改了之后提示group附近有语法错误呢
--  作者:有点蓝
--  发布时间:2020/5/5 15:04:00
--  
order by和group by 不能一起使用。其实直接的去掉order by即可,没有什么用,如果要排序

dt = cmd.ExecuteReader()
t1.Table.DataSource  =dt
t1.Table.sort = “物供号


--  作者:yetle
--  发布时间:2020/5/5 15:08:00
--  
去掉order by 还是有这个提示
--  作者:有点蓝
--  发布时间:2020/5/5 15:27:00
--  
select 里面出现的所有非集合函数用法的列名,都必须放到group by 里面。建议先分组,再进行计算,如

select  aa,bb,cc,dd,cc-dd as kk from (select aa,cc,dd,sum(bb) as bb from 表A group by aa,cc,dd) as a

1楼的sql也没看到有和分组有关的用法,把group by分组的用法去掉即可