MYSQL使用带有喜欢作为过滤器的选择语句 [英] MYsql using select statement with like as filter

查看:89
本文介绍了MYSQL使用带有喜欢作为过滤器的选择语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试使用select语句来过滤数据
我有一个文本框,它是like语句使用的值
用户登录并且该值存储在会话变量中并在select语句中使用我的问题是,如果我添加like子句,则我的select语句返回注释,因为like返回多个值.
这是我的选择声明

MySqlCommand sqlC = new MySqlCommand(从T_users中选择*,其中Serial_Number如@filterText,其中Company_Name =""+ CompanyName +"",myconfill);

@Filtertext是用户键入的任何内容,这是我在较早的代码中定义的参数


我如何解决@filtertext大于一个值然后不返回结果的问题.

Hallo everyone im trying to use a select statement to filter data
I have a textbox which is the value that the like statement uses
the user logs in and that value gets stored in an session variable and gets used in the select statement my problem is if I ad the like clause the my select statement returns noting because the like returns more than one value.
Here is my select statement

MySqlCommand sqlC = new MySqlCommand("select * from T_users where Serial_Number like @filterText and where Company_Name = ''" + CompanyName + "'' ", myconfill);

@Filtertext is whatever the user types in it is a parameter which I define in earlier code


How mould I get aroundd this problem of the @filtertext being more than one value then not returning a result

推荐答案

不,机会是LIKE语句不会返回注释,因为like返回多个值."

LIKE语句可能不会返回任何内容,因为它找不到任何匹配项.

LIKE需要通配符;没有它们,它的行为就像质量声明一样.
No, the chances are that the LIKE statement does not "returns noting because the like returns more than one value."

The chances are that the LIKE statement returns nothing because it finds no matches.

LIKE needs wildcard characters; without them it behaves exactly like an quality statement.
SELECT * FROM MyTable WHERE text LIKE 'hello'

返回与
完全相同的数据

returns exactly the same data as

SELECT * FROM MyTable WHERE text = 'hello'


如果要使用LIKE,则您的用户或您需要添加SQL通配符(例如与任何字符的零个或多个相匹配的%"):


If you want to use LIKE, then either your user or you need to add SQL wildcard characters (such as ''%'' which matches zero or more of any character):

SELECT * FROM MyTable WHERE text LIKE '%hello'

将找到所有以"hello"结尾的行.

Will find all rows ending with "hello"

SELECT * FROM MyTable WHERE text LIKE 'hello%'

将找到所有以"hello"开头的行.

Will find all rows starting with "hello"

SELECT * FROM MyTable WHERE text LIKE '%hello%'

将在某处找到所有带有"hello"的行.

Will find all rows with "hello" in there somewhere.


这篇关于MYSQL使用带有喜欢作为过滤器的选择语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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