Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
DavidChel
Constraint Violating Yak Guru
474 Posts |
Posted - 2008-07-23 : 16:21:27
|
| I know the basics of using the Like operator and the use of the % sign. However, how does one search for a string that actually contains the literal % in it. If I want to search for strings with actually start with "2%" and wanted to return records such as:2% Fuel Charge2% OffBut NOT 2 Dogs2 ChickensHow would I do this? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
DavidChel
Constraint Violating Yak Guru
474 Posts |
Posted - 2008-07-23 : 16:31:02
|
| All hail the Goddess. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-07-23 : 17:36:18
|
| [code]select xfrom ( --Test Data select x = '2%' union all select x = '2% Fuel Charge' union all select x = '2% Off' union all select x = '2 Dogs' union all select x = '2 Chickens' ) awhere x like '2^%%' escape '^'Results:x -------------- 2%2% Fuel Charge2% Off(3 row(s) affected)[/code]CODO ERGO SUM |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-24 : 02:35:38
|
| or as Tara sayscol like '2[%]%'MadhivananFailing to plan is Planning to fail |
 |
|
|
DavidChel
Constraint Violating Yak Guru
474 Posts |
Posted - 2008-07-24 : 09:17:33
|
| Thanks for the input folks. |
 |
|
|
|
|
|