More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Wednesday, 29 October 2014 2:47:27 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 522

SQL query with LIKE operator

match_expression [ NOT ] LIKE pattern [ ESCAPE escape_character ]

Wildcard characters

% - Any string of zero or more characters.
_ (underscore) - Any single character.
[ ] - Any single character within the specified range ([a-f]) or set ([abcdef]).
[^] - Any single character not within the specified range ([^a-f]) or set ([^abcdef]).


1. Pattern Matching with the ESCAPE Clause

examples in Delphi

Code:
function EscapeSqlLikeWildCard(const S, oldPattern, newPattern, strEscape: string) : string;
begin
  result := StringReplace(S, oldPattern, newPattern, [rfReplaceAll]) + ' ' + strEscape;
end;

function EscapeSqlLikeWildCards(const S : string) : string;
begin
  result := EscapeSqlLikeWildCard(S, '_', '\_', 'ESCAPE ''\''');
end;



2. Using Wildcard Characters As Literals

Symbol, Meaning
LIKE '5[%]', 5%
LIKE '[_]n', _n
LIKE '[a-cdf]', a, b, c, d, or f
LIKE '[-acdf]', -, a, c, d, or f
LIKE '[ [ ]', [
LIKE ']', ]
LIKE 'abc[_]d%', abc_d and abc_de
LIKE 'abc[def]', abcd, abce, and abcf

Examples:
finds Cheryl or Sheryl:
Code:
WHERE FirstName LIKE '[CS]heryl';


finds Zheng or Zhang:
Code:
WHERE LastName LIKE 'Zh[ae]ng'

Edited by user Wednesday, 29 October 2014 2:50:23 PM(UTC)  | Reason: Not specified

Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.