Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PetaPoco: How to use the SQL Like keyword ( WHERE Name LIKE '%@0%')

Tags:

What is the correct syntax for this query?

var l=db.Fetch<article>("SELECT * FROM articles WHERE title LIKE '%@0%'", 'something'); 

Or should I use CHARINDEX?

like image 656
Eduardo Molteni Avatar asked Aug 30 '11 03:08

Eduardo Molteni


People also ask

What is like keyword in SQL?

The SQL LIKE Operator The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.

How use varchar like in SQL?

The SQL LIKE operator is only applied on a field of types CHAR or VARCHAR to match a pattern. To match a pattern from a word, special characters, and wildcards characters may have used with LIKE operator. The LIKE operator can be used within any valid SQL statement, such as SELECT, INSERT INTO, UPDATE or DELETE.

When to use LIKE and equal in SQL?

LIKE is what you would use in a search query. It also allows wildcards like _ (simple character wildcard) and % (multi-character wildcard). = should be used if you want exact matches and it will be faster. Save this answer.

What is the difference between like and in SQL?

Example. Other than the difference of having wildcard characters, %, and _, there is a significant difference between LIKE and = operators is that LIKE operator does not ignore the trailing spaces while = operator ignores the trailing spaces.


2 Answers

May be

var l=db.Fetch<article>("SELECT * FROM articles WHERE title LIKE @0", "%something%");

like image 52
xdazz Avatar answered Oct 20 '22 19:10

xdazz


I haven't tried this, but I think it is worth trying:

var l=db.Fetch<article>("SELECT * FROM articles WHERE title LIKE @0", "%" + "something" + "%"); 
like image 30
Kevin Pullin Avatar answered Oct 20 '22 17:10

Kevin Pullin