sql-like

Emulating SQL LIKE in JavaScript

邮差的信 提交于 2019-11-27 04:07:49
How can I emulate the SQL keyword LIKE in JavaScript? For those of you who don't know what LIKE is, it's a very simple regex which only supports the wildcards % , which matches 0 or more characters, and _ which matches exactly one character. However, it's not just possible to do something like: var match = new RegEx(likeExpr.replace("%", ".*").replace("_", ".")).exec(str) != null; ...because the pattern might contain dots, stars and any other special regex characters. Chris Van Opstal What you have will work as long as you first escape the regex characters in your pattern. Below is one example

how to use a like with a join in sql?

怎甘沉沦 提交于 2019-11-27 03:58:54
问题 I have 2 tables, say table A and table B and I want to perform a join, but the matching condition has to be where a column from A 'is like' a column from B meaning that anything can come before or after the column in B: for example: if the column in A is 'foo'. Then the join would match if column in B is either: 'fooblah', 'somethingfooblah', or just 'foo'. I know how to use the wildcards in a standard like statement, but am confused when doing a join. Does this make sense? Thanks. 回答1: Using

Avoiding SQL Injection in SQL query with Like Operator using parameters?

左心房为你撑大大i 提交于 2019-11-27 03:53:48
问题 Taking over some code from my predecessor and I found a query that uses the Like operator: SELECT * FROM suppliers WHERE supplier_name like '%'+name+%'; Trying to avoid SQL Injection problem and parameterize this but I am not quite sure how this would be accomplished. Any suggestions ? note, I need a solution for classic ADO.NET - I don't really have the go-ahead to switch this code over to something like LINQ. 回答1: try this: var query = "select * from foo where name like @searchterm"; using

Using LIKE in an Oracle IN clause

限于喜欢 提交于 2019-11-27 03:50:58
问题 I know I can write a query that will return all rows that contain any number of values in a given column, like so: Select * from tbl where my_col in (val1, val2, val3,... valn) but if val1 , for example, can appear anywhere in my_col , which has datatype varchar(300), I might instead write: select * from tbl where my_col LIKE '%val1%' Is there a way of combing these two techniques. I need to search for some 30 possible values that may appear anywhere in the free-form text of the column.

How can I use 'Not Like' operator in MongoDB

♀尐吖头ヾ 提交于 2019-11-27 03:36:57
I used the SQL Like Operator using pymongo , db.test.find({'c':{'$regex':'ttt'}}) But how can I use Not Like Operator? I tried db.test.find({'c':{'$not':{'$regex':'ttt'}}) shx2 From the docs : The $not operator does not support operations with the $regex operator. Instead use // or in your driver interfaces, use your language’s regular expression capability to create regular expression objects. Consider the following example which uses the pattern match expression //: db.inventory.find( { item: { $not: /^p.*/ } } ) EDIT (@idbentley): {$regex: 'ttt'} is generally equivalent to /ttt/ in mongodb,

Which is faster — INSTR or LIKE?

≯℡__Kan透↙ 提交于 2019-11-27 03:34:39
If your goal is to test if a string exists in a MySQL column (of type 'varchar', 'text', 'blob', etc) which of the following is faster / more efficient / better to use, and why? Or, is there some other method that tops either of these? INSTR( columnname, 'mystring' ) > 0 vs columnname LIKE '%mystring%' FULLTEXT searches are absolutely going to be faster, as kibibu noted in the comments above. However : mysql> select COUNT(ID) FROM table WHERE INSTR(Name,'search') > 0; +-----------+ | COUNT(ID) | +-----------+ | 40735 | +-----------+ 1 row in set (5.54 sec) mysql> select COUNT(ID) FROM table

Is the LIKE operator case-sensitive with MSSQL Server?

 ̄綄美尐妖づ 提交于 2019-11-27 03:25:09
In the documentation about the LIKE operator , nothing is told about the case-sensitivity of it. Is it? How to enable/disable it? I am querying varchar(n) columns, on an Microsoft SQL Server 2005 installation, if that matters. It is not the operator that is case sensitive, it is the column itself. When a SQL Server installation is performed a default collation is chosen to the instance. Unless explicitly mentioned otherwise (check the collate clause bellow) when a new database is created it inherits the collation from the instance and when a new column is created it inherits the collation from

How can I optimize/refactor a TSQL “LIKE” clause?

时光怂恿深爱的人放手 提交于 2019-11-27 03:23:38
问题 I have a table with 117000 or so records. I need to perform a search that checks 3 separate fields for a given string pattern. My where clause is as follows: field1 LIKE '%' + @DESC + '%' OR field2 LIKE '%' + @DESC + '%' OR field3 LIKE '%' + @DESC + '%' This seems to take about 24 seconds regardless of input... Is there a better way to do this? Less than 10 (or 5!) seconds would be much more preferable. Thanks for any help. 回答1: Use Full Text Search and CONTAINS. LIKE cannot be optimized when

SQL Server datetime LIKE select?

给你一囗甜甜゛ 提交于 2019-11-27 02:57:08
in MySQL select * from record where register_date like '2009-10-10%' What is the syntax in SQL Server? 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 the appropriate DatePart code, e.g. AND DATEPART(hh, register_date) = 12) to get records made between 12 and

“Like” operator in inner join in SQL

陌路散爱 提交于 2019-11-27 02:12:38
问题 Using Sequel Pro, I have these two tables: Table1 Name Year x y John Smith 2010 10 12 Adam Jones 2010 8 13 John Smith 2011 7 15 Adam Jones 2011 9 14 etc. and Table2 Name Year z Smith John Smith John 2010 27 Jones Adam Jones Adam 2010 25 Smith John Smith John 2011 29 Jones Adam Jones Adam 2011 21 etc. Basically, the names in Table2 are the same only with the last name and first name switched, then repeated once. So the Names in Table1 are found in the names of Table2 ("John Smith" is found in