[英]SELECT with varying WHERE clause
I have the following Table (C# and MS Access):我有下表(C# 和 MS Access):
_sSqlString = "CREATE TABLE Device("
+ "deviceID AUTOINCREMENT NOT NULL,"
+ "brandName VARCHAR NOT NULL,"
+ "modelName VARCHAR NOT NULL,"
+ "deviceCaliber VARCHAR NOT NULL,"
+ "batterySize INT NOT NULL,"
+ "screenSize DOUBLE NOT NULL,"
+ "frontCameraMP INT NOT NULL,"
+ "rearCameraMP INT NOT NULL,"
+ "weightedScore INT,"
+ "PRIMARY KEY (deviceID)"
+ ")";
Table in MS Access with Populated Data带有填充数据的 MS Access 中的表
Goal:目标:
The User can select the Brands they prefer, which will do a SELECT command to find all devices that matches their preference.用户可以 select 他们喜欢的品牌,这将执行 SELECT 命令来查找所有符合他们喜好的设备。 The User can also select "Any Brand", which is a simple SELECT * command.
用户也可以 select “任何品牌”,这是一个简单的 SELECT * 命令。
User Interface Screenshot 1用户界面截图 1
User Interface Screenshot 2用户界面截图 2
What I have tried:我试过的:
Successfully: A SELECT procedure which passes in all the Brands, set to NULL if they are not selected.成功:一个 SELECT 程序,通过所有品牌,如果没有选择,则设置为 NULL。
While this works, I feel the repetition of OR is inefficient, and has the potential to be improved.虽然这行得通,但我觉得 OR 的重复效率低下,并且有改进的潜力。 Is it possible to improve this, or is a SELCT OR, OR, OR etc the best way?
是否有可能改善这一点,或者 SELCT OR、OR、OR etc 是最好的方法?
Thank you in advance for any help, it's very much appreciated: :)提前感谢您的任何帮助,非常感谢::)
Would using IN be appropriate here?在这里使用 IN 合适吗?
https://docs.microsoft.com/en-us/sql/t-sql/language-elements/in-transact-sql?view=sql-server-ver15 https://docs.microsoft.com/en-us/sql/t-sql/language-elements/in-transact-sql?view=sql-server-ver15
I'm not sure how you're going from C# to SQL here, but if you're just executing SQL you could concatenate a string of selected brands and use that in your select. I'm not sure how you're going from C# to SQL here, but if you're just executing SQL you could concatenate a string of selected brands and use that in your select. Point being you want a select that looks something like
要点是你想要一个看起来像的 select
SELECT *
FROM Device AS d
WHERE d.brandName IN ('Apple', 'Alcatel')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.