设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 4256|回复: 11
打印 上一主题 下一主题

[查询] 〔求助〕语句优化〔已解决〕

[复制链接]
1#
发表于 2010-7-28 20:30:46 | 显示全部楼层
本帖最后由 todaynew 于 2010-7-28 20:37 编辑
查询有四个条件:
厂家,状态,开始日期,结束日期
'--------------------------------------
strSql1 = ...
xuwenning 发表于 2010-7-28 16:46


简单问题何必复杂化呢?
dim ssql as string
dim swh as string
ssql = "SELECT * FROM tbl_表 where True "
swh=""
If isdate(Me.结束日期)=true then swh=swh & " and 日期 <=#" & Me. 结束日期 & "#"
If isdate(Me.开始日期)=true then swh=swh & " and 日期 >=#" & Me. 开始日期 & "#"
If isnull(Me.状态)=false then swh=swh & " and Flag=" & Me.状态
If isnull(Me.厂家)=false then swh=swh & " and 厂家='" & Me.厂家 & "'"
ssql=ssql & swh
2#
发表于 2010-7-29 09:23:30 | 显示全部楼层
为了加深理解,强烈要求xuwenning 同志重读《切掉尾巴》一文。
3#
发表于 2010-7-29 13:08:02 | 显示全部楼层
1=1太山寨了吧?true的可读性要强一些,也便于理解。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-18 05:48 , Processed in 0.084154 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表