Click here to Skip to main content
13,004,446 members (74,400 online)
Rate this:
Please Sign up or sign in to vote.
See more:
am trying to perform a search for this string
! @ # $ % ^ & * ( ) '

then i used the sql syntax
Select ID From Tasks Where task LIKE '[!] [@] [#] [$] [%] [^] [&] [*] [(] [)] ''%'

but i dont get any result, any help
Posted 15-Feb-13 1:33am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Probably you want:
SELECT ID FROM Tasks WHERE task LIKE '! @ # $ \% ^ & * ( ) ''%' ESCAPE '\'

"in the database, the data in the field is Today's Task"

Check again - I just created a SQLite DB, with a table Tasks and three entries:
ID(int) Task(nvarchar(50)
1	Hello
2	Today's Task
3	XX Today's Task XX

Then I hacked some C#:
string strCon = @"data source=D:\Temp\TestingSQLite.sldb";

SQLiteConnection con = new SQLiteConnection(strCon);
SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Tasks WHERE task LIKE '%Today''s Task%'", con);
DataTable dt = new DataTable();
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
And got two rows: 2, and 3.

Check your data!
Cool Smith 15-Feb-13 8:07am
hello, so even in other text, i only need to escape the % wilcard. say for example i need to search for "these are some wildcars & ! !" without the quote
OriginalGriff 15-Feb-13 8:25am
Yes - the only wildcards in SQLite LIKE comparisions are % and _ for "zero or more of any character" and "any single character" respectively, so they are the only ones you need to escape (except single quote, obviously!)
Cool Smith 15-Feb-13 9:29am
thank you very much. so even if i do this '%@! @@ @# $ @% @^ @& @* @( @) ''%', it doesn't have any negative effects right
OriginalGriff 15-Feb-13 9:34am
You might want to escape the "%" in the middle, but otherwise it's fine!
Cool Smith 15-Feb-13 9:44am
thank you very much
OriginalGriff 15-Feb-13 10:24am
You're welcome!
Marcus Kramer 15-Feb-13 10:20am
Cool Smith 15-Feb-13 11:43am
Hello I tried this statement
SELECT ID FROM Tasks WHERE task LIKE '%Today''s Task%'
and it failed to find the item, any idea what is wrong?
OriginalGriff 15-Feb-13 12:08pm
Without looking at your data? No idea at all! :laugh:
Cool Smith 15-Feb-13 12:10pm
in the database, the data in the field is Today's Task
OriginalGriff 15-Feb-13 12:26pm
Answer updated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 15 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100