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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 seaching for underscore _ ?

Author  Topic 

dwoolaver75
Starting Member

6 Posts

Posted - 2009-06-19 : 10:16:53
I had a situation where I needed to find all of the records in a varchar column that contained an underscore _.

Since the _ is also a wildcard character I could not use like '%_%', it returned no results.

I wound up doing the following and it seemed to work ok:

select * from items where replace(item_no,'_','@') like '%@%'

Is there a better way to do this? I'm just curious.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-19 : 12:27:43
select * from items where item_no like '%[_]%'


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

dwoolaver75
Starting Member

6 Posts

Posted - 2009-06-19 : 12:49:09
Excellent!
Returned the same number of records.
I should have thought of that.
Go to Top of Page
   

- Advertisement -