通过过滤器属性在整数字段中进行类似搜索 [英] Similar search in integer field by filter property

查看:81
本文介绍了通过过滤器属性在整数字段中进行类似搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ADODataSet,其中 Filtered属性设置为True(Filtered:=
True;)

I have a ADODataSet where the "Filtered" property is set to True (Filtered:= True;)

应用过滤器时:

[No] like '2%'

弹出错误无法打开过滤器。 [No]是
ADODataSet中整数类型的字段。当我将类似的过滤器应用于字符串列时,它可以正常工作。

an error "Filter can't be opened" pops up. [No] is a field in the ADODataSet of integer type. When I apply a similiar filter to string columns it works fine.

例如:

[LastName] like 'Jo%'. 

有什么想法吗?

谢谢。

推荐答案

我同意Ken的看法,如果您要查找20到29或200到299的数值,请根据价值。如果仍然要按照要求进行操作,请考虑tAdoDataSet的Filter属性与向查询中添加 where子句不同。使用服务器的语法在服务器端处理一个子句。另一方面,Filter属性是在您的软件中解析的,并且具有自己的语法规则。

I agree with Ken, if you're looking for numeric values 20 through 29 or 200 through 299, then search based on the values. If you still want to do as you ask, consider that the Filter property of a tAdoDataSet is not identical to adding a "where" clause to your query. A where-clause would be dealt with on the server side, using the server's syntax. The Filter property, on the other hand, is parsed within your software and has its own syntax rules.

选择之一是使用实际的从句。在测试中,我使用的是MS SQL Server。我将SQL文本更改为:

Option one is to use an actual where-clause. In my test I'm using MS SQL Server. I changed the SQL text to:

select [LASTNAME], [NO] from PEOPLE
where [NO] like '2%'

在这种情况下,MSSQL的语法规则会将数字值转换为字符应用过滤器之前的字符串。

In this case, the syntax rules for MSSQL will cast the numeric value to a character string before applying the filter.

选项二是更改查询以返回字符串。

Option two is to alter the query to return a string.

select [LASTNAME], [NO],
cast ( [NO] as varchar(20) ) as [NO_AS_CHAR] 
from PEOPLE

然后将过滤器更改为

[NO_AS_CHAR] like '2%'

这篇关于通过过滤器属性在整数字段中进行类似搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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