sql-like

Using JOIN statement with CONTAINS function

微笑、不失礼 提交于 2019-12-10 18:16:27
问题 In SQL Server database I have a View with a lot of INNER JOINs statements. The last join uses LIKE predicate and that's why it's working too slowly. The query looks like : SELECT * FROM A INNER JOIN B ON A.ID = B.ID INNER JOIN C ON C.ID1 = B.ID1 INNER JOIN ........................... X ON X.Name LIKE '%' + W.Name + '%' AND LIKE '%' + W.Name2 + '%' AND LIKE '%' + W.Name3 + '%' I want to use CONTAINS instead of LIKE as : SELECT * FROM A INNER JOIN B ON A.ID = B.ID INNER JOIN C ON C.ID1 = B.ID1

sql like query slow if using declare parameter but fast if not

点点圈 提交于 2019-12-10 16:54:47
问题 SQL 2008: This is slow (takes 1 1/2 minutes): declare @p1 varchar(50) set @p1 = '976j%' select * from invsearch_query where comparepnfwd like @p1 This takes less than a second: select * from invsearch_query where comparepnfwd like '976j%' Why??? 回答1: I would imagine that you must have a non covering index with leading column comparepnfwd that is used by the literal query but not by the query with the variable. You can use OPTION (RECOMPILE) to get SQL Server to recompile the plan taking into

search by substring in documentDB

≡放荡痞女 提交于 2019-12-10 14:18:48
问题 this is the sample documentDB document, I want to get all the documents who failed in one or more subjects I found something like SELECT * FROM students s JOIN c IN s.subjects WHERE c.result = "pass" I want to retrieve by using c# code { "id": "0066a253-f042-4213-b06e-65b1ea1e49aa", "name": "Sunny", "rollNo": 123, "class": "2nd", "section": "B", "Department": { "name": "CSE", "id": "cse", "subjects": [ { "id": "subject-1", "marksObtained": 66, "maxMarks": 100, "result": "pass" }, { "id":

How use “LIKE” and “%” to check similarity to variable in android(Java code)

ⅰ亾dé卋堺 提交于 2019-12-10 11:53:07
问题 I am working on Android app using Java, I need to query database in Java code to check if userinput(variable) statement is contain words which are in my SQLite DataBase using LIKE in query and rowQuery method in java code, I used this code but it did not work: cursor = db.rawQuery("SELECT shompet FROM sentence WHERE " + column + " LIKE '%" + newMessage + "%'", null); newMessage is my variable(userInput) I read similar topics but either they are not my answer or they are so complicated. 回答1:

MySQL LIKE operators & wildcards

不问归期 提交于 2019-12-10 11:46:00
问题 I've been reading tutorials and have learned nothing new. I have a table of customers. The customer's first and last names are stored in separate columns. I want to write a query that can search for customers by name, either first, last or BOTH. Here's what I've got: $queryyy = " SELECT * FROM `customers` WHERE `first_name1` LIKE '".mysql_real_escape_string($_GET['custname'])."%' OR `last_name1` LIKE '%".mysql_real_escape_string($_GET['custname'])."' AND `status` = 'active' LIMIT 6 "; If I

T-SQL speed comparison between LEFT() vs. LIKE operator

痴心易碎 提交于 2019-12-10 01:14:40
问题 I'm creating result paging based on first letter of certain nvarchar column and not the usual one, that usually pages on number of results. And I'm not faced with a challenge whether to filter results using LIKE operator or equality ( = ) operator. select * from table where name like @firstletter + '%' vs. select * from table where left(name, 1) = @firstletter I've tried searching the net for speed comparison between the two, but it's hard to find any results, since most search results are

How can LIKE '%…' seek on an index?

巧了我就是萌 提交于 2019-12-09 11:13:37
问题 I would expect these two SELECT s to have the same execution plan and performance. Since there is a leading wildcard on the LIKE , I expect an index scan. When I run this and look at the plans, the first SELECT behaves as expected (with a scan). But the second SELECT plan shows an index seek, and runs 20 times faster. Code: -- Uses index scan, as expected: SELECT 1 FROM AccountAction WHERE AccountNumber LIKE '%441025586401' -- Uses index seek somehow, and runs much faster: declare @empty

MySQL LIKE limiting

不羁的心 提交于 2019-12-09 07:16:24
Basicly I have a row in my table, that has the following format for it's value - 1,2,3,4,10,11,21,34 etc.. I'm retrieving values with LIKE statement, but since I'm using it with %<value>% , when searching for 1 it returns 11, 21, 1 and so on. How can I limit it, to return values based on one? Instead of col LIKE '%<value>%' do col LIKE '%,<value>,%' OR col LIKE '<value>,%' OR col LIKE '%,<value>' OR col LIKE '<value>' or better yet col REGEXP '(.+,|^)<val>(,.+|$)' But the best solution is to change your data structure! Either use the SET type, or several fields, or a join table. Try the find

SQL LIKE operator with parameters and wildcards

大城市里の小女人 提交于 2019-12-08 18:45:13
问题 I have a query where I want to return all Clients that have a certain string in the name with wildcards on either side. So the input could be "Smith" and i want to return all things like "The John Smith Company" or "Smith and Bros". I want [Client] to be prompted so I set up the SQL like this: PARAMETERS Client Text ( 255 ); SELECT * WHERE (((tbl_IncomingChecks.Client) Like'%' + [Client] + '%') ORDER BY tbl_IncomingChecks.Client; The query is not returning any results. Please help 回答1: MS

How can I use the Like Operator with a Parameter in a SQLite query?

早过忘川 提交于 2019-12-08 17:28:38
问题 I can get the result I expect by entering this in LINQPad: SELECT * FROM WorkTable WHERE WTName LIKE "DSD__20090410014953000%" (it shows me the record which has a WTName value of DSD__20090410014953000.xml") But trying to do this programmatically is proving trying. I tried: const string qry = "SELECT SiteNum FROM WorkTable WHERE WTName LIKE @wtName%"; using (SQLiteConnection con = new SQLiteConnection(HHSUtils.GetDBConnection())) { con.Open(); SQLiteCommand cmd = new SQLiteCommand(qry, con);