Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

in string

Status
Not open for further replies.

nyzja

Programmer
Jan 13, 2005
31
US
Hi! Does SQL Server have an equivalent of the inStr function in Access? Basically, I need to evaluate a field if it has a specific string. For example, I need to know if there is "DDD" in the string "ERTGDDDE".

Please help. Thanks!
 
MOF, yes, there is.

There are a couple of methods. The first is

Code:
Select * from MyTable where MyField like '%DDD%'

The % sign is SQL's wildcard.

PatIndex and CharIndex can return position numbers within a string where your pattern occurs.



Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
 
Code:
select patindex('DDD', 'ERTGDDDE')
See PATINDEX in BOL.

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(Not quite so old any more.)
 
The closest T-SQL thing to VB-like inStr() function is CHARINDEX().

PATINDEX() works with patterns, so wildcard characters (%, _, blah) are interpreted different way.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top