Newsgroups: microsoft.public.sqlserver.programming
From: "Anith Sen" <an...@bizdatasolutions.com>
Date: Tue, 28 Jan 2003 09:21:30 -0600
Local: Tues, Jan 28 2003 10:21 am
Subject: Re: get rid of invalid chars from phone number field.
Here are some general methods which you can use for such string replacement
requirements. 1. Using REPLACE A very common method is to use multiple REPLACE functions in your UDPATE DECLARE @BadStr VARCHAR(30) 2. CASE expressions If the string is limited in length, you can use a series of CASE DECLARE @BadStr VARCHAR(30) SELECT CASE WHEN SUBSTRING(@BadStr, 1, 1) LIKE '[0-9]' 3. T-SQL UPDATE extn. Another intuitive way of doing such conversions is to use another table SELECT * Now do: DECLARE @BadStr VARCHAR(30) You can make this a permanent table and use it for general data cleanup 4. Scalar UDF In SQL 2000, you can use a scalar UDF which can remove all the expleteves CREATE FUNCTION dbo.ufn_onlydigits (@StrVal AS VARCHAR(8000)) Usage: In other SQL versions, depending on what you are doing, you can also make -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||