Solved

SQL Server Query PatIndex Question

Posted on 2011-09-06
3
394 Views
Last Modified: 2012-05-12
Hello all,

I have a function as shown here that is stripping out any non alphanumeric characters except the plus (+) sign.  I run an update statement against the whole table currently where I say for example:

Update Customer Set CustomerNumber = dboKeepNonAlphaCharacters(CustomerNumber)

The problem is this table has millions of rows so the logs grow when doing this and performance is slowed.  How can I only update those records that have a non alphanumberic number like shown below to only update that subset of records to keep the log down?


Alter Function [dbo].[KeepNonAlphaCharacters](@Temp VarChar(35)) Returns VarChar(35)
 AS
 Begin
While PatIndex('%[^a-zA-Z0-9+]%', @Temp) > 0 --AND PatIndex('+', @Temp) > 0
Set @Temp = Stuff(@Temp, PatIndex('%[^a-zA-Z0-9+]%', @Temp), 1, '')
Return @Temp
 End

0
Comment
Question by:sbornstein2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36493410
Add a WHERE clause. Try with:
your_column_to_clean LIKE '%[^a-zA-Z0-9+]%'

You can also do it with the PATINDEX(), but I would try it with the LIKE.
0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 250 total points
ID: 36493419
In other words, like this:

UPDATE your_table
SET your_column_to_clean = dbo.KeepNonAlphaCharacters(your_column_to_clean)
WHERE your_column_to_clean  LIKE '%[^a-zA-Z0-9+]%'

Open in new window

0
 

Author Closing Comment

by:sbornstein2
ID: 36493443
cool thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question