| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 452 人关注过本帖
标题:谁能看一下下面的SQL语句有没有错啊?
只看楼主 加入收藏
风云105047
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-3-30
收藏
 问题点数:0 回复次数:2 
谁能看一下下面的SQL语句有没有错啊?

Private Sub Query()

If all = False Then
If Text2 = "" And text3 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '" _
& strcgmc & "%'"
ElseIf Text1 = "" And text3 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '" _
& strwcdw & "%'"
ElseIf Text1 = "" And Text2 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjldj like '" _
& strhjdj & "%'"
ElseIf Text1 = "" And Text2 = "" And text3 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjlsj like '" _
& strhjsj & "%'"
ElseIf Text1 = "" And Text2 = "" And text3 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where zywcrs like '%" & strwcr & "%'"

ElseIf Text1 = "" And Text2 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjldj like '" & strhjdj & "%' and nsbjlsj like '" & strhjsj & "%'"
ElseIf Text1 = "" And text3 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "%' and nsbjlsj like '" & strhjsj & "%'"
ElseIf Text1 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "%' and nsbjldj like '" & strhjdj & "%'"
ElseIf Text2 = "" And text3 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "%' and nsbjlsj like'" & strhjsj & "%'"
ElseIf Text2 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "%' and nsbjldj like'" & strhjdj & "%'"
ElseIf text3 = "" And text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "%' and wcdw like'%" & strwcdw & "%'"
ElseIf Text1 = "" And Text2 = "" And text3 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjlsj like '" & strhjsj & "%' and zywcrs like '%" & strwcr & "%'"

ElseIf Text2 = "" And text3 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "%' and zywcrs like '%" & strwcr & "%'"

ElseIf Text1 = "" And Text2 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjldj like '" & strhjdj & "%' and zywcrs like '%" & strwcr & "%'"

ElseIf Text1 = "" And text3 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '" & strwcdw & "%' and zywcrs like '%" & strwcr & "%'"

ElseIf Text1 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "%' and nsbjlsj like '" & strhjsj & "%' and nsbjldj like '" & strhjdj & "%'"
ElseIf Text2 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "%' and nsbjlsj like '" & strhjsj & "%' and nsbjldj like '" & strhjdj & "%'"
ElseIf text3 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "%' and nsbjlsj like '" & strhjsj & "%' and wcdw like '" & strwcdw & "%'"
ElseIf text4 = "" And Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "%' and cgmcz like '%" & strcgmc & "%' and nsbjldj like '" & strhjdj & "%'"
ElseIf Text1 = "" And Text2 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where (nsbjldj like '" & strhjdj & "% ') and (nsbjlsj like '" & strhjsj & "%') and (zywcrs like '" & strwcr & "%')"


ElseIf Text1 = "" And text3 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & " 'and nsbjlsj like '" & strhjsj & " 'and zywcrs like '%" & strwcr & "%'"

ElseIf Text1 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjldj like '" & strhjdj & " ' and wcdw like '%" & strwcdw & "%' and zywcrs like '%" & strwcr & "%'"
ElseIf Text2 = "" And text3 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjlsj like '" & strhjsj & " 'and cgmcz like '%" & strcgmc & "%' and zywcrs like '%" & strwcr & "%'"

ElseIf Text2 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where nsbjldj like '" & strhjdj & " 'and cgmcz like '%" & strcgmc & "%' and zywcrs like '%" & strwcr & "%'"

ElseIf text3 = "" And text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & " 'and cgmcz like '%" & strcgmc & "%' and zywcrs like '%" & strwcr & "%'"

ElseIf Text1 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "' and nsbjldj like '" & strhjdj & " 'and nsbjlsj like'" & strhjsj & "%' and zywcrs like '%" & strwcr & "%'"

ElseIf Text2 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "' and nsbjldj like '" & strhjdj & " 'and nsbjlsj like'" & strhjsj & "%'and zywcrs like '%" & strwcr & "%'"

ElseIf text3 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "' and cgmcz like '%" & strcgmc & " 'and nsbjlsj like'" & strhjsj & "%' and zywcrs like '%" & strwcr & "%'"

ElseIf text4 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where wcdw like '%" & strwcdw & "' and nsbjldj like '" & strhjdj & " 'and cgmcz like'%" & strcgmc & "%' and zywcrs like '%" & strwcr & "%'"

ElseIf Text5 = "" Then
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like '%" & strcgmc & "' and wcdw like '%" & strwcdw & "' and nsbjldj like '" & strhjdj & "%'and nsbjlsj like'" & strhjsj & "%' "

Else
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT where cgmcz like'%" & strcgmc & "%' and wcdw like '%" & strwcdw & "%' and nsbjlsj like'" & strhjsj & "%'and nsbjldj like'" & strhjdj & "%' and zywcrs like '%" & strwcr & "%'"

End If
Else
strsql = "select cgbh as 成果编号,cgmcz as 成果名称,wcdw as 完成单位,nsbjldj as 获奖等级,nsbjlsj as 获奖时间 from CGZT"
End If

'strcgmc,strwcdw,strcgdj,strhjsj变量是前面定义的公共变量,用来传递查询窗体中的成果名称,完成单位,获奖等级,获奖时间
Adodc1.RecordSource = strsql
Adodc1.Refresh
DataGrid1.Rebind
rs.Open strsql, conn, adOpenKeyset, adLockPessimistic
Adodc1.RecordSource = strsql
Adodc1.Refresh
DataGrid1.Rebind
If rs.EOF = True And rs.BOF = True Then
MsgBox "没有找到您所需要的结果!", vbOKOnly + vbInformation, "注意"
rs.Close
Exit Sub
End If
rs.Close
'End If
End Sub

搜索更多相关主题的帖子: SQL 语句 
2006-03-30 13:09
风云105047
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-3-30
收藏
得分:0 

问题是每次查询时,只要是两种情况还行,可一查询三种以上的情况,就查不出来,这是为什么阿?


卧梅又问花 我智慧中天 与闻卧失水
2006-03-30 13:13
风云105047
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-3-30
收藏
得分:0 
各位高手帮一下吧?

卧梅又问花 我智慧中天 与闻卧失水
2006-03-30 16:32
快速回复:谁能看一下下面的SQL语句有没有错啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029182 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved