如何使用in子句中的msd访问条件进行选择 [英] How to use in clause in where condtion for selection in ms access

查看:110
本文介绍了如何使用in子句中的msd访问条件进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MS Access 2007中的in子句为select数据编写查询。



我尝试了什么:



我的查询是



从InvoiceInfo中选择*,其中[InvoiceNo]包含('INV0001,INV0010')



但它返回0行,其中在访问表中该值存在

I write a query for select data using in clause from MS Access 2007.

What I have tried:

my query is

Select * from InvoiceInfo where [InvoiceNo] contains ('INV0001,INV0010')

but its return 0 rows, where in access table this values is exists

推荐答案

您正在检查特定的string:INV0001,INV0010所以除非那个确切的字符串 - 即两个用逗号分隔的发票号 - 位于至少一行中,否则你将不会返回任何行。你不会得到其中一个发票号或其他号码的行,或找到的行,但也用空格分隔。



如果你的DB包含逗号分开的发票编号,它设计得很糟糕:你应该使用一个单独的表,其中包含每个发票号以及一个与原始表相关的外键 - 并使用JOIN查询获取数据。



如果没有,你可能需要一个IN子句:

You are checking for a specific string: "INV0001,INV0010" so unless that exact string - i.e. both invoice numbers separated by a comma - is located in at least one row you will get no rows returned. You will not get rows where one of the invoice numbers or the other are found, or where there are found but also separated by a space.

If your DB contains comma separated invoice numbers, that it's badly designed: you should be using a separate table that contains each single invoice number together with a Foreign Key that relates back to your original table instead - and fetch data using a JOIN query.

If it doesn't, you may need an IN clause instaed:
SELECT * FROM InvoiceInfo WHERE InvoiceNo IN ('INV0001', 'INV0010');


你能尝试这样吗



Can you try like this

SELECT *
FROM InvoiceInfo
WHERE InvoiceNo IN('INV0001','INV0002','INV0003');


这篇关于如何使用in子句中的msd访问条件进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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