sql-like

How to Use 'Like' with a parameter

99封情书 提交于 2019-11-28 09:57:19
问题 I want to search for a number embedded in a string in a field in our log table using a parameter. select * from vwLogs where log_time >'02/24/2009' and message like ('%2009022508241446%') I know how to use parameters when the where clause is an equals sign but not sure how to do it with 'Like' this doesn't seem right WHERE message like ('%@ErrorMessage%') I just tried this and it didn't work. The only thing new is the message search part protected void btnRunQuery_Click(object sender,

SQLite Like % and _

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 09:34:56
I can't figure out what the underscore character does in an SQLite like statement. The wildcard character, % , is probably the same as in most other SQL databases. So, what does the damn _ character do? The underscore is also the same as in most other SQL databases and matches any single character (i.e. it is the same as . in a regular expression). From the fine manual : An underscore ("_") in the LIKE pattern matches any single character in the string. For example: -- The '_' matches the single 'c' sqlite> select 'pancakes' like 'pan_akes'; 1 -- This would need '__' to match the 'ca', only

Like operator for integer

拈花ヽ惹草 提交于 2019-11-28 09:18:54
I have a column of type bigint (ProductSerial) in my table. I need to filter the table by the Product serial using like operator. But I found that, like operator can't be used for integer type. Is there any other method for this (I don't want to use the = operator). If you must use LIKE , you can cast your number to char / varchar , and perform the LIKE on the result. This is quite inefficient, but since LIKE has a high potential of killing indexes anyway, it may work in your scenario: ... AND CAST(phone AS VARCHAR(9)) LIKE '%0203' If you are looking to use LIKE to match the beginning or the

How do I perform a case-sensitive search using LIKE?

a 夏天 提交于 2019-11-28 08:55:21
I'm trying to find records that contain a string of 6 or more alpha-numeric characters in uppercase. Some examples: PENDING 3RDPARTY CODE27 I'm using the following statement: SELECT Details FROM MyTable WHERE Details LIKE '%[0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z]%'; This is returning all records that contain any 6-or-more-letter word, regardless of case. I've added a COLLATE statement: SELECT Details FROM MyTable WHERE Details COLLATE Latin1_General_CS_AS LIKE '%[0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z]%'; This changes nothing. It still returns records with 6-or-more-letter

Is it possible to perform a “LIKE” statement in a SSIS Expression?

泪湿孤枕 提交于 2019-11-28 08:25:44
I'm using a Derived Column Task to change column data using a CASE WHEN statement. However, I need to be able to say.. SQL CODE WOULD BE: CASE WHEN Column01 LIKE '%i%' THEN '0' ELSE '1' END In SSIS Expression Language that would be: [Column01] == "i" ? "0" : "1" (that's for equals i, not, LIKE %i%. Is it possible to use a LIKE operator? I believe you'll want to use the FINDSTRING function . FINDSTRING(character_expression, searchstring, occurrence) ... FINDSTRING returns null if either character_expression or searchstring are null. Guilherme de Jesus Santos I know it is an old question, but

linq to entities generated sql

独自空忆成欢 提交于 2019-11-28 07:48:21
问题 I am having some problems with linq to entities in the ado.net entity framework. Basically what I'm doing is this: var results = (from c in companies where c.Name.StartsWith(letter) select c); and this gets translated to SQL as something like: WHERE (CAST(CHARINDEX(@p, [Extent1].[Name]) AS int)) = 1 which is fine but my table has millions of records so this runs VERY slow. What I need it to generate is something like: WHERE Name LIKE @p + '%' I'm searched high and low and cannot find any

How to use 'LIKE' statement with unicode strings?

寵の児 提交于 2019-11-28 07:38:04
问题 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:

How to query lucene with “like” operator? [duplicate]

匆匆过客 提交于 2019-11-28 07:34:34
This question already has an answer here: Leading wildcard character throws error in Lucene.NET 3 answers The wildcard * can only be used at the end of a word, like user* . I want to query with a like %user% , how to do that? Lucene provides the ReverseStringFilter that allows to do leading wildcard search like *user. It works by indexing all terms in reverse order. But I think there is no way to do something similar to 'LIKE %user%'. The trouble with LIKE queries is that they are expensive in terms of time taken to execute. You can set up QueryParser to allow leading wildcards with the

Regular expression to match start of filename and filename extension

不问归期 提交于 2019-11-28 05:58:22
What is the regular expression to match strings (in this case, file names) that start with 'Run' and have a filename extension of '.py'? The regular expression should match any of the following: RunFoo.py RunBar.py Run42.py It should not match: myRunFoo.py RunBar.py1 Run42.txt The SQL equivalent of what I am looking for is ... LIKE 'Run%.py' ... . For a regular expression, you would use: re.match(r'Run.*\.py$') A quick explanation: . means match any character. * means match any repetition of the previous character (hence .* means any sequence of chars) \ is an escape to escape the explicit dot

MySQL LIKE with range doesn't work

▼魔方 西西 提交于 2019-11-28 02:21:39
I've got a database table mytable with a column name in Varchar format, and column date with Datetime values. I'd like to count names with certain parameters grouped by date. Here is what I do: SELECT CAST(t.date AS DATE) AS 'date', COUNT(*) AS total, SUM(LENGTH(LTRIM(RTRIM(t.name))) > 4 AND (LOWER(t.name) LIKE '%[a-z]%')) AS 'n' FROM mytable t GROUP BY CAST(t.date AS DATE) It seems that there's something wrong with range syntax here, if I just do LIKE 'a%' it does count properly all the fields starting with 'a'. However, the query above returns 0 for n, although should count all the fields