How to search wildcards character in string

No.of Views1110
Bookmarked0 times
Downloads 
Votes0
By  youngmurukan   On  15 Feb 2010 21:02:15
Tag : Sql Servers , T-SQL
How to search wildcards character in string
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 


If you need to search for actual underscore or percent characters in a string, you can use the
ESCAPE option to identify those characters.
For example,

'%\%%' ESCAPE '\'

The character after the ESCAPE tells the database how to differentiate between characters to
search for and wildcards, and in the example the backslash character (\) is used.
The first % is treated as a wildcard and matches any number of characters;
the second % is treated as an actual character to search for;
the third % is treated as a wildcard and matches any number of characters.

The following query uses the promotions table, which contains the details for products being
discounted by the store .
The query uses the LIKE operator to search the name column of the promotions table for the values whatever starts or ends with '%' character.

SELECT name
FROM promotions
WHERE name LIKE '%\%%' ESCAPE '\';

The results would be as shown below,

NAME
------------------------------
10% off Z Files
20% off Pop 3
30% off Modern Science
 
Sign Up to vote for this article
 
About Author
 
youngmurukan
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Not Provided
Joined date-12 May 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top