如何在SELECTION查询中使用IF条件? [英] How do i use an IF condition in a SELECTION query?

查看:104
本文介绍了如何在SELECTION查询中使用IF条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在尝试编写一个选择查询来过滤日期的记录列表。字段值是BETWEEN最小值和最大值。这些值必须从表格中取得,如果它们不是空的。如果它们是空的,则查询必须返回整个未过滤的列表。

我不知道如何在SELECT .... WHERE函数中插入IF条件。


非常感谢您的关注

Hi everybody,

i''m trying to write a selection query that filters a list of records which the "date" field value is BETWEEN a minimum and a maximum values. These values must be taken from a form IF they are not empty. If they are empty the query must return the whole unfilterd list.
I don''t know how to insert an IF condition in a SELECT....WHERE function.

Many thanks for your attention

推荐答案

我不确定您是否可以在SQL语句中完成此操作,坦率地说,我是''不是要问的人。您可以做的是动态创建一个Query,根据名为txtDOB的表单字段是否为Null有条件地构建SQL Source语句。以下代码将基于名为tblEmployees的Employee表动态创建名为New Query的Query。如果出生日期字段([txtDOB])为空,则从tblEmployees返回所有记录。如果出生日期字段不为空,则返回其出生日期介于1970年1月1日至1970年12月31日之间的所有员工记录。
I''m not sure if you can accomplish this in an SQL Statement, and quite frankly, I''m not the one to ask. What you can do is to dynamically create a Query, conditionally building the SQL Source Statement based on whether or not a Form Field named txtDOB is Null or not. The following Code will dynamically create a Query named ''New Query'' based on an Employee Table named tblEmployees. If a Date of Birth Field ([txtDOB]) Is Null, then all Records are returned from tblEmployees. If the Date of Birth Field is Not Null, then all Employee Records whose whose date of Birth falls between 1/1/1970 and 12/31/1980 are returned.
展开 | 选择 | Wrap | 行号


看看这个帖子,特别是帖子#6
http://bytes.com/topic/access/answer...ria-expression

我想这可以解决你的问题。
Take a look at this thread, especially to post #6
http://bytes.com/topic/access/answer...ria-expression
I think that can manage your problem.


MMMh ..我按照你的建议尝试了这个新查询总是为空,是否是字符串太长或其他什么问题?
MMMh.. i tried this as you suggested but the new query is always empty, is it a problem with a too long string or what else?
展开 | 选择 | Wrap | 行号


这篇关于如何在SELECTION查询中使用IF条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆