sql-like

Match '%' sign when searching in MySQL database

前提是你 提交于 2019-12-18 06:13:53
问题 I would like to match this 'wildcard %' in MySQL. I tried using escape \% and it is not working. 回答1: The default escape character is \ . So just prefix % with a \ as: \% : The manual clearly says: To test for literal instances of a wild-card character, precede it by the escape character. If you do not specify the ESCAPE character, “\” is assumed. Search for % in Stack%Overflow : mysql> select 'Stack%Overflow' like '%\%%'; +------------------------------+ | 'Stack%Overflow' like '%\%%' | +---

LIKE and NULL in WHERE clause in SQL

时光怂恿深爱的人放手 提交于 2019-12-18 05:42:48
问题 I have a store procedure which i have planned to use for search and get all values. Scenario: If the parameter passed is NULL it should return all the values of the table and if the parameter passed is not NULL it should return the values according to the condition which is in LIKE. //Query: ALTER procedure [dbo].[usp_GetAllCustomerDetails] ( @Keyword nvarchar(20) = null ) As Begin Select CustomerId,CustomerName,CustomerTypeName,CustomerCode,CategoryName,CustomerMobile,CustomerEmail

Why I need to double-escape (use 4 \) to find a backslash ( \ ) in pure SQL?

对着背影说爱祢 提交于 2019-12-18 05:12:15
问题 I do not understand this MySQL behaviour : if I want to display a\b, I can just select "a\\b" which work without problem : mysql> select "a\\b"; +-----+ | a\b | +-----+ | a\b | +-----+ 1 row in set (0.05 sec) But if I wnat to search a string containing a \ in a table using LIKE, I need to double-escape my "\". Why ? Here is an example. We prepare a small table. create table test ( test varchar(255) ); insert into test values ( "a\\b" ) , ( "a\\b\\c" ) , ( "abcd" ); mysql> select * from test;

LIKE query using multiple keywords from search field using PDO prepared statement

佐手、 提交于 2019-12-17 22:03:12
问题 Site users use a search form to query a database of products. The keywords entered search the titles for the products in the database. public function startSearch($keywords){ $keywords = preg_split('/[\s]+/', $keywords); $totalKeywords = count($keywords); foreach($keywords as $key => $keyword){ $search .= '%'.$keyword.'%'; if($key != ($totalKeywords)-1){ $search .= ' AND itemTitle LIKE '; } } $sql=$this->db->prepare("SELECT * FROM prodsTable WHERE itemTitle LIKE ?"); $sql->bindParam(1,

Is it possible to perform a “LIKE” statement in a SSIS Expression?

﹥>﹥吖頭↗ 提交于 2019-12-17 18:38:44
问题 I'm using a Derived Column Task to change column data using a CASE WHEN statement. However, I need to be able to say.. SQL CODE WOULD BE: CASE WHEN Column01 LIKE '%i%' THEN '0' ELSE '1' END In SSIS Expression Language that would be: [Column01] == "i" ? "0" : "1" (that's for equals i, not, LIKE %i%. Is it possible to use a LIKE operator? 回答1: I believe you'll want to use the FINDSTRING function. FINDSTRING(character_expression, searchstring, occurrence) ... FINDSTRING returns null if either

How to query lucene with “like” operator? [duplicate]

五迷三道 提交于 2019-12-17 18:28:10
问题 This question already has answers here : Leading wildcard character throws error in Lucene.NET (3 answers) Closed 6 years ago . The wildcard * can only be used at the end of a word, like user* . I want to query with a like %user% , how to do that? 回答1: Lucene provides the ReverseStringFilter that allows to do leading wildcard search like *user. It works by indexing all terms in reverse order. But I think there is no way to do something similar to 'LIKE %user%'. 回答2: The trouble with LIKE

MySQL LIKE with range doesn't work

十年热恋 提交于 2019-12-17 17:28:54
问题 I've got a database table mytable with a column name in Varchar format, and column date with Datetime values. I'd like to count names with certain parameters grouped by date. Here is what I do: SELECT CAST(t.date AS DATE) AS 'date', COUNT(*) AS total, SUM(LENGTH(LTRIM(RTRIM(t.name))) > 4 AND (LOWER(t.name) LIKE '%[a-z]%')) AS 'n' FROM mytable t GROUP BY CAST(t.date AS DATE) It seems that there's something wrong with range syntax here, if I just do LIKE 'a%' it does count properly all the

Python String Formats with SQL Wildcards and LIKE

我怕爱的太早我们不能终老 提交于 2019-12-17 09:51:24
问题 I'm having a hard time getting some sql in python to correctly go through MySQLdb. It's pythons string formatting that is killing me. My sql statement is using the LIKE keyword with wildcards. I've tried a number of different things in Python. The problem is once I get one of them working, there's a line of code in MySQLdb that burps on string format. Attempt 1: "SELECT tag.userId, count(user.id) as totalRows FROM user INNER JOIN tag ON user.id = tag.userId WHERE user.username LIKE '%%s%'" %

Use of SqlParameter in SQL LIKE clause not working

ぃ、小莉子 提交于 2019-12-17 08:34:30
问题 I have the following code: const string Sql = @"select distinct [name] from tblCustomers left outer join tblCustomerInfo on tblCustomers.Id = tblCustomerInfo.CustomerId where (tblCustomer.Name LIKE '%@SEARCH%' OR tblCustomerInfo.Info LIKE '%@SEARCH%');"; using (var command = new SqlCommand(Sql, Connection)) { command.Parameters.AddWithValue("@SEARCH", searchString); ... } This does not work, I tried this as well: const string Sql = @"select distinct [name] from tblCustomers left outer join

MySQL - How to search for exact word match using LIKE?

主宰稳场 提交于 2019-12-17 07:30:10
问题 I'm using this query to select data: mysql_query("SELECT * FROM products WHERE product_name LIKE '%".$search."%'"); The only problem is, that it sometimes selects more, than I would like. For example, I would like to select product "BLA", but my query select product "BLABLA" as well. To be clear, if i wanted to select "Product 1", I don't want the query to select "Product 11". Does anybody know how to manage that? Thanks. 回答1: Do you just want to search on word boundaries? If so a crude