sql-like

How to write like statements in Entity Framework when the liked valued contains %

…衆ロ難τιáo~ 提交于 2020-01-16 04:55:08
问题 I know that String.Contains('x') would translate to LIKE '%x%' , and String.StartsWith('x') and String.EndsWith('x') would translate into LIKE '%x' and LIKE 'x%' respectively. However, I'm now in a situation in which I'm gonna build the LIKE operator regular expression clause in the business layer, and send it to the SQL Server through Entity Framework. I mean, now the end users builds the regular expression through a GUI and we need to retrieve the result based on that. For example, user

How to use LIKE statement with multiple values from another field?

寵の児 提交于 2020-01-16 00:35:29
问题 I want to select all records where field contains values from another field. How do I do that? Here is a code that I am trying. select field1 , field2, field3 from table1 where field1 like '%'+(select distinct field4 from table2)+'%' Thanks in advance. 回答1: Just do your like as a join condition: select field1 , field2, field3 from table1 join (select distinct field4 from table2) x on field1 like '%'+field4+'%' 回答2: Using the original structure of your query, you can do: select field1, field2,

Compare values of two columns

孤者浪人 提交于 2020-01-15 22:12:10
问题 Is there a way to compare the values of two columns in MySQL? For example if I have a table: +----------------+ | Col1 | Col2 | |----------------| | abc | 123abc | | def | 234def | | | 123ghi | +----------------+ And I wanted to retrieve all the entries in Col2 that contained the values of Col1 : +---------+ | NewCol | |---------| | 123abc | | 234def | +---------+ How would I go about that? Here is a pseudo-query to explain a bit further. SELECT Col2 FROM TableName WHERE Col2 LIKE Col1; 回答1:

mysql query with like %..% in the where clause returning different results

♀尐吖头ヾ 提交于 2020-01-14 03:18:32
问题 I have the following problem (using mysql 5.0.70). In one table I have a varchar field containing some kind of a number, like: "0303A342", "21534463", "35663CE3" etc. Collation is set to utf8_general_ci . The problem shows up when a user of the system is trying to search for a record containing part of this number. SQL query looks like ... WHERE 'number' LIKE '%0303A%' Now if the 'A' in the LIKE part is entered as a Latin A, the result contains only records with Latin A's in them -- as it

T-SQL special characters to escape for LIKE operator wildcard search

故事扮演 提交于 2020-01-12 15:52:10
问题 SQL Server has the LIKE operator to handle wildcard searches. My customer wants to use the "*" (asterisk) character in the user interface of an application as the wildcard character. I'm just wondering if there are any standard characters that I need to worry about (that are used as special characters in SQL Server) besides the "%" (percent) character itself before performing a LIKE wilcard search in case their keyword contains a "%" and needs to find a "%" in the actual string. If so, what

T-SQL special characters to escape for LIKE operator wildcard search

扶醉桌前 提交于 2020-01-12 15:52:08
问题 SQL Server has the LIKE operator to handle wildcard searches. My customer wants to use the "*" (asterisk) character in the user interface of an application as the wildcard character. I'm just wondering if there are any standard characters that I need to worry about (that are used as special characters in SQL Server) besides the "%" (percent) character itself before performing a LIKE wilcard search in case their keyword contains a "%" and needs to find a "%" in the actual string. If so, what

SQL: Is it possible to 'group by' according to 'like' function's results?

会有一股神秘感。 提交于 2020-01-12 14:26:08
问题 I am using Oracle SQL and I want to group some different rows that 'like' function results. To elaborate with an example: Let's assume I have a table MESA with one of the columns is a huge string. And I am counting the number of rows matching particular patterns: SELECT m.str, count(*) FROM MESA m WHERE m.str LIKE '%FRUIT%' AND (m.str LIKE '%APPLE%' OR m.str LIKE '%ORANGE%') So let's assume the result of this query is: FRUIT..afsafafasfa...RED_APPLE 20 FRUIT..afsafafasfa...YELLOW_APPLE 12

SQL 'LIKE' query using '%' where the search criteria contains '%'

爱⌒轻易说出口 提交于 2020-01-09 06:52:04
问题 I have an SQL query as below. Select * from table where name like '%' + search_criteria + '%' If search_criteria = 'abc', it will return data containing xxxabcxxxx which is fine. But if my search_criteria = 'abc%', it will still return data containing xxxabcxxx , which should not be the case. How do I handle this situation? 回答1: If you want a % symbol in search_criteria to be treated as a literal character rather than as a wildcard, escape it to [%] ... where name like '%' + replace(search

SQL Server datetime LIKE select?

折月煮酒 提交于 2020-01-08 19:03:11
问题 in MySQL select * from record where register_date like '2009-10-10%' What is the syntax in SQL Server? 回答1: You could use the DATEPART() function SELECT * FROM record WHERE (DATEPART(yy, register_date) = 2009 AND DATEPART(mm, register_date) = 10 AND DATEPART(dd, register_date) = 10) I find this way easy to read, as it ignores the time component, and you don't have to use the next day's date to restrict your selection. You can go to greater or lesser granularity by adding extra clauses, using

How to use JOIN LIKE with AND Operator in SQL Server? [duplicate]

人盡茶涼 提交于 2020-01-07 06:18:46
问题 This question already has an answer here : 'LIKE' clause with 'AND' operator in SQL Server 2012 (1 answer) Closed 3 years ago . Look at this scenario first: I have table1 with column C1 and 2 records in it with values Text1 and Text2. SELECT * FROM TabelX INNER JOIN table1 ON TableX.Name LIKE '%'+table1.C1+'%' This code means: SELECT * FROM TabelX WHERE TableX.Name LIKE '%Text1%' OR TableX.Name LIKE '%Text2%' Now how can I change JOIN LIKE that means AND not OR? Something like: SELECT * FROM