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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

test if string contains a character

Status
Not open for further replies.

dky1e

Programmer
May 4, 2002
293
US
Is there a funtion to test if a string contains a character specified? Similar to IndexOf function in .net sdk?

Here's my pseudo code:
declare @test
select @test = 'asdf'
if indexOf( @test, 'a' ) > 0
begin
do stuff
end
 
PRINT patindex ('%[A-Za-z]%','123a')
will return 4

PRINT patindex ('%[A-Za-z]%','123')
will return 0
 
So if you are looking for 'a' replace the

%[A-Za-z]% with %a%

for case insensitive do %[Aa]%

Use both % (wildcards in SQL) unless you want a field that starts with a: [aA]% or ends with a: %[Aa]
 
how would I use it if I am using variables?
How do I use the '%' character?
 
here we go... I found an alternative.
SELECT CHARINDEX('w', 'wonderful')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top