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 |
|
venkath
Posting Yak Master
202 Posts |
Posted - 2008-09-26 : 07:03:15
|
| Hi allThe data in the column is as followsCOL----pr_view1prview2pr_view3I want to search the data that starts with 'pr_%'For the queryselect col from tablw where col like 'pr_%'I am getting all the 3 records.Please help me how to search data with underscore letterThanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 07:09:57
|
| select col from tablw where col like 'pr%' and charindex('_',col)>0 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-26 : 07:18:18
|
| You need to escape itwhere col like 'pr[_]%'MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-26 : 07:20:15
|
quote: Originally posted by visakh16 select col from tablw where col like 'pr%' and charindex('_',col)>0
That wont do the job exactly and would fail for the data like prvi_ew2, prview_2,etcMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 07:23:21
|
quote: Originally posted by madhivanan
quote: Originally posted by visakh16 select col from tablw where col like 'pr%' and charindex('_',col)>0
That wont do the job exactly and would fail for the data like prvi_ew2, prview_2,etcMadhivananFailing to plan is Planning to fail
yup...it wont work in all cases |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-26 : 07:30:32
|
| Other method is to use escape keywordwhere col like 'pr__%' escape '_'MadhivananFailing to plan is Planning to fail |
 |
|
|
venkath
Posting Yak Master
202 Posts |
Posted - 2008-09-26 : 08:22:50
|
| Thank you all for your response |
 |
|
|
|
|
|