sql-like

how to select record whose matching percentage is higher than other using like operator in sql server?

北城余情 提交于 2019-12-01 09:21:23
问题 I have set of records which I need to search using criteria. But criteria is returning me multiple rows. So I need top 2 records which are having maximum percentage of criteria matching. I worked on fuzzy logic but found that it is too complex for such simple problems. I have scenarios like below: SELECT DISTINCT FirstName, LastName, CountryName, StateName FROM Employee Say for example above one is returning me 5 records. What I want is like use "like" operator thru which I can find that

Is Contains Equivalent To Like In SQL Server

僤鯓⒐⒋嵵緔 提交于 2019-12-01 08:53:38
When I'm running this query: Select * from Table1 Where Column1 Like 'aaa%' --3 Result Select * from Table1 Where Column1 Like 'a%' --3 Result Select * from Table1 Where Column1 Like 'A%' --3 Result but when I'm running Select * from Table1 Where Contains(Column1 ,'aaa') --3 Result Select * from Table1 Where Contains(Column1 ,'a') --0 Result Select * from Table1 Where Contains(Column1 ,'A') --0 Result CONTAINS can search for: As Per MSDN A word or phrase. The prefix of a word or phrase. A word near another word. Does that mean that Contains can't search for letters? If yes, then how? Edit2:

LIKE not working in TSQL

强颜欢笑 提交于 2019-12-01 08:40:43
问题 Consider this TSQL: declare @b varchar(100) set @b = 'BANK-41' IF @b LIKE 'BANK_%' BEGIN print 'Wrong Matching' END Why does the TSQL match the string " BANK- " and " BANK_ "? 回答1: In TSQL the underscore is a wildcard representing a single char. In order to escape in you need to wrap it with square brackets, like this: 'BANK[_]%' See this page: http://www.dirigodev.com/blog/web-development-execution/escaping-percent-and-underscore-characters-in-t-sql-like-clause/ 回答2: An underscore in SQL

Is Contains Equivalent To Like In SQL Server

末鹿安然 提交于 2019-12-01 05:48:56
问题 When I'm running this query: Select * from Table1 Where Column1 Like 'aaa%' --3 Result Select * from Table1 Where Column1 Like 'a%' --3 Result Select * from Table1 Where Column1 Like 'A%' --3 Result but when I'm running Select * from Table1 Where Contains(Column1 ,'aaa') --3 Result Select * from Table1 Where Contains(Column1 ,'a') --0 Result Select * from Table1 Where Contains(Column1 ,'A') --0 Result CONTAINS can search for:As Per MSDN A word or phrase. The prefix of a word or phrase. A word

How to prioritize a LIKE query select based on string position in field?

梦想的初衷 提交于 2019-12-01 05:13:49
I am attempting to query a table for a limited resultset in order to populate an autocomplete field in javascript. I am, therefore, using a LIKE operator with the partial string entered. If I have, for example, a table such as: tblPlaces id country 1 Balanca 2 Cameroon 3 Canada 4 Cape Verde 5 Denmark For the sake of this example, let's say I want two rows returning - and yeah, for this example, I made up a country there ;) I want to prioritize any instance where a partial string is matched at the beginning of country. The query I began using, therefore is: SELECT id, country FROM tblPlaces

Why do we need the GLOB clause in SQLite?

蓝咒 提交于 2019-12-01 03:23:06
I'm an Android developer and recently came across the GLOB clause in SQLite. I cannot understand why we need GLOB given that LIKE is already in place. Both clauses have wildcards to represent single and multiple characters. The only difference is that GLOB is case sensitive. But is that all? Are there any queries where LIKE is a bad or inappropriate choice? Are there any cases where we absolutely have to use GLOBE vs LIKE or vice versa? Case sensitivity is useful by itself, because this works better with normal indexes. Additionally, GLOB supports character classes: Globbing rules: * Matches

Sql query with special characters - how to handle?

瘦欲@ 提交于 2019-12-01 00:20:15
I've few emp names like john,1 devil's corn something like this Now when i'm searching for these names I'm using select * from emp where empname like ('john,1,devil's,corn') But I'm not getting expected values also I'm getting error because emp name contains special charecters like , and '. Can someone help me out how to solve this? This assumes you have 3 discrete names in your example string Exact match. you need to double up quotes. select * from emp where empname IN ('john,1' , 'devil''s', 'corn') You can't LIKE/IN in SQL Server too. select * from emp where empname like '%john,1%' OR

Returning records that partially match a value

╄→尐↘猪︶ㄣ 提交于 2019-11-30 22:30:33
I'm trying to get a query working that takes the values (sometimes just the first part of a string) from a form control. The problem I have is that it only returns records when the full string is typed in. i.e. in the surname box, I should be able to type gr, and it brings up green grey graham but at present it's not bringing up anything uless the full search string is used. There are 4 search controls on the form in question, and they are only used in the query if the box is filled in. The query is : SELECT TabCustomers.*, TabCustomers.CustomerForname AS NameSearch, TabCustomers

MS Access SQL LIKE query from C#

ぐ巨炮叔叔 提交于 2019-11-30 22:01:40
I have this query for Ms Access and im using C# and Ole DB commands. It works on Ms Access but when I'm passing the query from C# using OleDB, nothing happened. Anyway here's my code: SQL query SELECT * FROM tblIssue WHERE id LIKE '*2*' AND dateChecque LIKE '**'AND + issueTo LIKE '**' AND byTheName LIKE '**' AND bankName LIKE '**' AND accountNo LIKE '**' + AND checqueNo LIKE '**' AND amount LIKE '**' AND being LIKE '**' AND whoDeleted LIKE '**' + AND whyDeleted LIKE '**' AND dateCreated LIKE '**'; C# code try { DataTable newDt = new DataTable(); OleDbDataAdapter newSda = new OleDbDataAdapter

Simulating LIKE in PHP

情到浓时终转凉″ 提交于 2019-11-30 20:21:43
Is there a way to simulate the LIKE operator of SQL in PHP with the same syntax? ( % and _ wildcards and a generic $escape escape character)? So that having: $value LIKE $string ESCAPE $escape you can have a function that returns the PHP evaluation of that without using the database? (consider that the $value , $string and $escape values are already set). OK, after much fun and games here's what I have come up with: function preg_sql_like ($input, $pattern, $escape = '\\') { // Split the pattern into special sequences and the rest $expr = '/((?:'.preg_quote($escape, '/').')?(?:'.preg_quote(