查询以检查字段中是否存在某个值 [英] query to check if a certain value does exist in a field

查看:142
本文介绍了查询以检查字段中是否存在某个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我需要检查字段中是否存在某个值,并返回

是和是。或不或哪个查询最节能?

If I need to check if a certain value does exist in a field, and return
either "yes" or "not" which query would be the most effestive?

推荐答案

aa写道:
如果我需要检查某个值是否确实存在于一个字段中,并返回是和是。或不或哪个查询最节能?
If I need to check if a certain value does exist in a field, and
return either "yes" or "not" which query would be the most effestive?




什么数据库?喷射? SQL Server?别的什么?在没有告诉我们您正在使用什么数据库的情况下,永远不要求查询

援助。


您想查看某个记录是否包含该字段中的值吗?或者

你想知道任何记录是否包含该值吗?


你为什么要关心查询在假期时有多么有趣? ;-)

(好吧,这是一个愚蠢的笑话,但我不能让节能只是通过

无条件< grin>)


Bob Barrows


-

Microsoft MVP - ASP / ASP.NET

请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我

不经常检查它。如果您必须离线回复,请删除

没有垃圾邮件



What database? Jet? SQL Server? Something else? Never ask for query
assistance without telling us what database you are using.

Do you want to see if a certain record contains the value in the field? Or
do you want to see if ANY record contains that value?

And why do you care how much fun the query has at holiday time? ;-)
(OK, that was a dumb joke, but I could not let "effestive" simply pass
unignored <grin>)

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don''t check it very often. If you must reply off-line, then remove the
"NO SPAM"


对不起,Access 2000 - 我认为应该是一个核心SQL独立于

特定实现。

我想看看表列中是否存在某个值。所以我将这个

值传递给查询并返回布尔值是或否。

如果可能,我不需要记录集。


ps你为什么要关心查询在假期时有多么有趣? ; - )"

我正在以其他方式工作 - 周末加上Monadays工作和

在工作日休假


Bob Barrows <再****** @ NOyahoo.SPAMcom>在消息中写道

新闻:eA ************* @ TK2MSFTNGP12.phx.gbl ...
Sorry, Access 2000 - I thought that should be a core SQL independent of a
particular implementation.
I want to see if there is a certain value in a table column. So I pass this
value to a query and return Boolean yes or not.
If possible, I do not need a recordset.

ps "And why do you care how much fun the query has at holiday time? ;-)"
I am working trhe other way round - working on weekends plus Monadays and
having holiday on the weekdays

"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:eA*************@TK2MSFTNGP12.phx.gbl...
aa写道:
如果我需要检查字段中是否存在某个值,并返回是和是。或不或哪个查询最节能?
If I need to check if a certain value does exist in a field, and
return either "yes" or "not" which query would be the most effestive?



什么数据库?喷射? SQL Server?别的什么?在不告诉我们您正在使用什么数据库的情况下,永远不要求查询帮助。

您想查看某个记录是否包含该字段中的值?或者你想知道任何记录是否包含该值吗?

为什么你关心查询在假期时有多么有趣? ;-)
(好吧,这是一个愚蠢的笑话,但我不能让节日化简单地传递
无条件< grin>)

Bob Barrows
-
Microsoft MVP - ASP / ASP.NET
请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我不经常检查它。如果您必须离线回复,请删除
NO SPAM



What database? Jet? SQL Server? Something else? Never ask for query
assistance without telling us what database you are using.

Do you want to see if a certain record contains the value in the field? Or
do you want to see if ANY record contains that value?

And why do you care how much fun the query has at holiday time? ;-)
(OK, that was a dumb joke, but I could not let "effestive" simply pass
unignored <grin>)

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don''t check it very often. If you must reply off-line, then remove the
"NO SPAM"



aa写道:
对不起,Access 2000 - 我认为这应该是一个特定实现的核心SQL独立。
我想看看表列中是否有某个值。
Sorry, Access 2000 - I thought that should be a core SQL independent
of a particular implementation.
I want to see if there is a certain value in a table column.



我再说一遍:你想检查所有行吗?还是特定的一排?


哦,没关系。以下是您可以在任何一种情况下使用的解决方案:

使用此sql创建一个名为qCheckCol的已保存查询:

从表WHERE中选择count(*) search_column = pSearchValue


然后,在asp中,执行以下操作:

dim conn,rs,SearchVal,bValExists

set conn = server.createobject(" adodb.connection")

conn.open sConnectionString

set rs = server.createobject(" adodb.recordset")

conn.qCheckCol SearchVal,rs

bValExists = cbool(rs(0).value)

rs.close:set rs = nothing

conn.close:set conn = nothing

response.write bValExists


如果您只想检查特定行,请向WHERE添加更多条件

条款用于识别您要检查的特定行。


HTH,

Bob Barrows

-

Microsoft MVP - ASP / ASP.NET

请回复新闻组。这个电子邮件帐户是我的垃圾邮件陷阱所以我

不经常检查它。如果您必须离线回复,请删除

无垃圾邮件


I repeat: do you want to check ALL rows? or a particular row?

Oh, never mind. Here''s a solution you can use in either case:

Create a saved query called qCheckCol with this sql:
Select count(*) from table WHERE search_column = pSearchValue

Then, in asp, do this:
dim conn, rs, SearchVal, bValExists
set conn=server.createobject("adodb.connection")
conn.open sConnectionString
set rs=server.createobject("adodb.recordset")
conn.qCheckCol SearchVal, rs
bValExists = cbool(rs(0).value)
rs.close:set rs=nothing
conn.close:set conn=nothing
response.write bValExists

If you only want to check a particular row, add more criteria to the WHERE
clause to identify the particular row you wish to check.

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don''t check it very often. If you must reply off-line, then remove the
"NO SPAM"


这篇关于查询以检查字段中是否存在某个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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