x

Search for Characters in SQL server 2000 or 2005

Please guide me below mentioned problem

String1 = ÁĚĎ String2 = PQĎ

I need to find out whether any of the characters in string1 appears in string2. My fuction should exit the loop at the first occurance of any of the string1 character in string2. I do not want to process each of the character in string1 in a loop as i have to process millions of records in the database. Can anyone guide me what sql statement can be written in sql server 2000 or sql server 2005.

With Regards

Novice

more ▼

asked Nov 06, 2009 at 06:30 AM in Default

SQLserver_novice gravatar image

SQLserver_novice
113 6 6 7

(comments are locked)
10|1200 characters needed characters left

3 answers: sort voted first
SELECT PATINDEX('%[abc]%', 'This is a test')

That will return 9 - the 1-based index of the first occurrance of any of the letters a, b or c

more ▼

answered Nov 06, 2009 at 07:46 AM

Matt Whitfield gravatar image

Matt Whitfield ♦♦
29.4k 61 65 87

(comments are locked)
10|1200 characters needed characters left

Have you thought of using full-text indexing and using the CONTAINS function?

more ▼

answered Nov 06, 2009 at 07:30 AM

Mark Allison gravatar image

Mark Allison
479 1 1 4

(comments are locked)
10|1200 characters needed characters left

I know it's an old post, Ben, but did either of these answers solve your problem?

more ▼

answered Mar 07, 2010 at 01:17 PM

Jeff Moden gravatar image

Jeff Moden
1.7k 2 4 8

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1945
x985
x473

asked: Nov 06, 2009 at 06:30 AM

Seen: 2146 times

Last Updated: Nov 06, 2009 at 06:50 AM