sql-like

Use LIKE %..% with field values in MySQL

て烟熏妆下的殇ゞ 提交于 2019-11-30 06:17:31
问题 I stumbled into a delicate SQL problem when I needed to use a value from a field inside a LIKE %..% statement. Example: SELECT t1.Notes, t2.Name FROM Table1 t1, Table2 t2 WHERE t1.Notes LIKE '%t2.Name%' This is only an example from the top of my head to show what I need to do (I know this will not work). I need to use the value of t2.Name inside the LIKE %..% I guess this is trivial when you know it ;) 回答1: Use: SELECT t1.Notes, t2.Name FROM Table1 t1 JOIN Table2 t2 ON t1.Notes LIKE CONCAT('%

Using LIKE operator with stored procedure parameters

馋奶兔 提交于 2019-11-30 03:29:29
I have a stored procedure that uses the LIKE operator to search for a truck location among some other parameters @location nchar(20), @time time, @date date AS select DonationsTruck.VechileId, Phone, Location, [Date], [Time] from Vechile, DonationsTruck where Vechile.VechileId = DonationsTruck.VechileId and (((Location like '%'+@location+'%') or (Location like '%'+@location) or (Location like @location+'%') ) or [Date]=@date or [Time] = @time) I null the other parameters and search by location only but it always returns no results even when I used the full name of the location Your datatype

SELECT * FROM tbl WHERE clm LIKE CONCAT('%',<other sql query LIMIT 1>,'%') - HOW?

梦想的初衷 提交于 2019-11-30 03:25:20
问题 How can I combine those two queries into one? 1) This finds the japanese sign for dog (犬): SELECT japanese FROM edict WHERE english LIKE 'dog' LIMIT 1; 2) This finds all japanese words with the sign for 'dog' (犬) in it: SELECT japanese FROM edict WHERE japanese LIKE '%犬%'; 3) I am having trouble combining those two into one, because this doesn't work?! SELECT japanese FROM edict WHERE japanese LIKE CONCAT('%', SELECT japanese FROM edict WHERE english LIKE 'dog' LIMIT 1,'%' ); 回答1:

doctrine2 dql, use setParameter with % wildcard when doing a like comparison

*爱你&永不变心* 提交于 2019-11-29 23:25:47
I want to use the parameter place holder - e.g. ?1 - with the % wild cards. that is, something like: "u.name LIKE %?1%" (though this throws an error). The docs have the following two examples: 1. // Example - $qb->expr()->like('u.firstname', $qb->expr()->literal('Gui%')) public function like($x, $y); // Returns Expr\Comparison instance I do not like this as there is no protection against code injection. 2. // $qb instanceof QueryBuilder // example8: QueryBuilder port of: "SELECT u FROM User u WHERE u.id = ?1 OR u.nickname LIKE ?2 ORDER BY u.surname DESC" using QueryBuilder helper methods $qb-

How to escape underscore character in PATINDEX pattern argument?

坚强是说给别人听的谎言 提交于 2019-11-29 22:37:34
I've found a solution for finding the position of an underscore with PATINDEX : DECLARE @a VARCHAR(10) SET @a = '37_21' PRINT PATINDEX('%_%', @a) -- return 1 (false) PRINT PATINDEX('%!%', REPLACE(@a, '_', '!')) -- return 3 (correct) Have you other ideas? Like a way to escape the underscore character? Curt Hagenlocher I've always done it with brackets: '%[_]%' To match two underscores, each must be bracketed '%[__]%' -- matches single _ with anything after '%[_][_]%' -- matches two consecutive _ Charlie You can escape using the [ and ] characters like so: PRINT PATINDEX('%[_]%', '37_21') 来源:

PostgreSQL: Select data with a like on timestamp field

£可爱£侵袭症+ 提交于 2019-11-29 22:15:17
I am trying to select data from a table, using a "like" on date field "date_checked" (timestamp). But I have this error : SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: timestamp without time zone My request is : SELECT my_table.id FROM my_table WHERE my_table.date_checker LIKE '2011-01-%' I don't want to use : SELECT my_table.id FROM my_table WHERE my_table.date_checker >= '2011-01-01 00:00:00' AND my_table.date_checker < '2011-02-01 00:00:00' It's all very well not "wanting to use" < and > with timestamps, but those operators can be converted into index scans, and a

How to make “LIKE” query work in MongoDB?

ぐ巨炮叔叔 提交于 2019-11-29 20:43:52
问题 I have a list of street names and I want to select all that start with "Al". In my MySQL I would do something like SELECT * FROM streets WHERE "street_name" LIKE "Al%" How about MongoDB using PHP? 回答1: Use a regular expression: db.streets.find( { street_name : /^Al/i } ); or: db.streets.find( { street_name : { $regex : '^Al', $options: 'i' } } ); http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions Turning this into PHP: $regex = new MongoRegex("/^Al/i");

SQL- Ignore case while searching for a string

时光毁灭记忆、已成空白 提交于 2019-11-29 20:13:12
I have the following data in a Table PriceOrderShipped PriceOrderShippedInbound PriceOrderShippedOutbound In SQL I need to write a query which searches for a string in a table. While searching for a string it should ignore case. For the below mentioned SQL query SELECT DISTINCT COL_NAME FROM myTable WHERE COL_NAME LIKE '%PriceOrder%' gives all the above data, whereas SELECT DISTINCT COL_NAME FROM myTable WHERE COL_NAME LIKE '%Priceorder%' doesn't give. Eg. when I search for 'PriceOrder' or 'priceOrder' it works but 'priceorder' or 'Priceorder' doesn't work. I have tried with the below query

SQL Server, combining % and [] wildcards in LIKE statement

强颜欢笑 提交于 2019-11-29 19:53:01
问题 In t-sql, is there a way to do pattern matching in a like statement such that you can search for 1 or more characters in a given set? To be specific, I'm trying to come up with a LIKE statement that will return strings that begin with 1 or more letters and end in 1 or more numbers. So these strings should match: abcd1234 a1 abcdef2 ab123456 And these strings should not match: abcd 1234 abcd1234abcd 1abcd1 I know you can use the % wildcard to match a string of 0 or more characters, and you can

How to use 'LIKE' statement with unicode strings?

牧云@^-^@ 提交于 2019-11-29 13:50:02
I am trying to execute a query with unicode characters. I was able to execute the normal equality query by prepending N to the query (Eg: ..... WHERE column=N'exact_stringâ' ). But that doesn't seem to work when I try to use LIKE . Any ideas on how to make this work? Sample query: SELECT * FROM t_sample WHERE t_column LIKE N'%â%' Also how can I know which encoding does the SQL Server use to store the nvarchar or nchar data type and what encoding it uses to show the query in SQL Editor? EDIT: My bad. This actually works. I have tried executing the query in a wrong window. But the upside of this