Need To Strip Non-numerics From Phone Field
Jul 22, 2004
I tried searching forums for the last hour and could not find much.
Rather then doing...
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(RE PLACE(ISNULL(PHONE, ''), ' ', ''), '(', ''), ')', ''), '-', ''), '.', ''), ':', ''), '+', '')
I was hoping there was an equally efficient alternative that utilizes PATINDEX('%[^0-9]%', PHONE)
to some capacity (i.e. uses regular expressions to strip all non-numeric characters from the phone field)
I am certain this has been addressed before, just not sure if the "REPLACE to the nth degree" is the only solution.
THANKS!
View 7 Replies
ADVERTISEMENT
May 8, 2008
Hi,
I'm trying to create a case function for home phone ,work phone and cell phone. The thing is some of the home phone numbers either null, zero or less than 10 digits then i'd like to get either cell phone or work phone if they are not null, zero or less than 10 digits.
I'd appreciate it if you could help me on this?
Thanks in advance.
View 19 Replies
View Related
Nov 8, 2001
hey,
what the best way of stripping out a list of characters from a specified field in a table. e.g If first name consists of ABCD'E-FSA, we wnat to strip the ' and the -. There is about 15-20 characters like that.
what's the best way of doing it other encapsulating in the replace function that many times.
thanks
zoey
View 2 Replies
View Related
Dec 3, 2004
Hi all,
I have a table that I've imported into SQL - there is a field in there for date that must have used now(); as its default value (access).
So the values are something like:
01/11/2004 12:16:42
I need a way to change the data so that the time element removed is the field just holds the date. Failing that a way to insert this from the existing field into a new field stripping the date off en route would be a great help.
Many thanks
Phil
View 2 Replies
View Related
Feb 21, 2006
Hello,
I have a phone number field with the format (123)-456-7890 I need to convert this to 1234567890 formats while I am retrieving data from the table. How can I do this?
View 4 Replies
View Related
Jan 17, 2005
Hi,
I need to formate one of my phone number field in SQL. now the data in the field is: 1234567890. I would like to formate the number to 123-456-7890. Does anyone know how to do this? Thanks.
Nicole
View 5 Replies
View Related
Nov 27, 2007
I had a problem with the ntext datatype. I need to strip the HTML tags out of a ntext datatype column. I have sample query for that, which works fine for STRING, as stuff is the string function, what to do for ntext field.
=======The Process follows like this =========
--**************************************
--
-- Name: A relational technique to strip
-- the HTML tags out of a string
-- Description:A relational technique to
-- strip the HTML tags out of a string. Th
-- is solution demonstrates how to use simp
-- le tables & search functions effectively
-- in SQL Server to solve procedural / ite
-- rative problems.
-- This table contains the tags to be re
-- placed. The % in <head%>
-- will take care of any extra informati
-- on in the tag that you needn't worry
-- about as a whole. In any case, this t
-- able contains all the tags that needs
-- to be search & replaced.
CREATE TABLE #html ( tag varchar(30) )
INSERT #html VALUES ( '<html>' )
INSERT #html VALUES ( '<head%>' )
INSERT #html VALUES ( '<title%>' )
INSERT #html VALUES ( '<link%>' )
INSERT #html VALUES ( '</title>' )
INSERT #html VALUES ( '</head>' )
INSERT #html VALUES ( '<body%>' )
INSERT #html VALUES ( '</html>' )
go
-- A simple table with the HTML strings
CREATE TABLE #t ( id tinyint IDENTITY , string varchar(255) )
INSERT #t VALUES (
'<HTML><HEAD><TITLE>Some Name</TITLE>
<LINK REL="stylesheet" HREF="/style.css" TYPE="text/css" ></HEAD>
<BODY BGCOLOR="FFFFFF" VLINK="#444444">
SOME HTML text after the body</HTML>'
)
INSERT #t VALUES (
'<HTML><HEAD><TITLE>Another Name</TITLE>
<LINK REL="stylesheet" HREF="/style.css"></HEAD>
<BODY BGCOLOR="FFFFFF" VLINK="#444444">Another HTML text after the body</HTML>'
)
go
-- This is the code to strip the tags out.
-- It finds the starting location of eac
-- h tag in the HTML string ,
-- finds the length of the tag with the
-- extra properties if any. This is
-- done by locating the end of the tag n
-- amely '>'. The same is done
-- in a loop till all tags are replaced.
BEGIN TRAN
WHILE exists(select * FROM #t JOIN #html on patindex('%' + tag + '%' , string ) > 0 )
UPDATE #t
SET string = stuff( string , patindex('%' + tag + '%' , string ) ,
charindex( '>' , string , patindex('%' + tag + '%' , string ) )
- patindex('%' + tag + '%' , string ) + 1 , '' )
FROM #t JOIN #html
ON patindex('%' + tag + '%' , string ) > 0
SELECT * FROM #t
rollback
View 1 Replies
View Related
Sep 10, 2001
I have a phone number field.
I would like to remove the hypens and brackets.
Do anyone know of any functions, I can use to accomplish this??
Thanks in advance!
--Vic
View 1 Replies
View Related
Aug 3, 2006
Hi everyone -
I need to remove the formatting characters
from the phone field in the database.
The data entry scrubber did not perform correct,
and now, a LOT of records have the ( in the field.
Is there a quick way to remove the ( from the field in the database??
MSSQL 2000
thanks
tony
View 1 Replies
View Related
Apr 1, 1999
Hi - just found this site yesterday. Does anyone have experience converting a numeric(11,2) column to a 'mainframe' format with 'trailing sign overpunch'. Any old mainframe programmers will recognize this: there is no punctuation (- or + or , or .) and if the sign is negative, the last character is } for 0, J for 1, K for 2, etc.
I wrote the following command to convert the 'openrtl' column, but is there some other way?
oprtl =
CASE
WHEN openretl >= 0 THEN str((abs(openretl*100)),11,0)
WHEN openretl < 0 THEN substring(str((abs(openretl*100)),11,0),1,10) +
CASE
WHEN substring(str((abs(openretl*100)),11,0),11,1) = '0'
THEN '}'
WHEN substring(str((abs(openretl*100)),11,0),11,1) = '1'
THEN 'J'
WHEN substring(str((abs(openretl*100)),11,0),11,1) = '2'
THEN 'K'
WHEN substring(str((abs(openretl*100)),11,0),11,1) = '3'
THEN 'L'
WHEN substring(str((abs(openretl*100)),11,0),11,1) = '4'
THEN 'M'
WHEN substring(str((abs(openretl*100)),11,0),11,1) = '5'
THEN 'N'
WHEN substring(str((abs(openretl*100)),11,0),11,1) = '6'
THEN 'O'
WHEN substring(str((abs(openretl*100)),11,0),11,1) = '7'
THEN 'P'
WHEN substring(str((abs(openretl*100)),11,0),11,1) = '8'
THEN 'Q'
WHEN substring(str((abs(openretl*100)),11,0),11,1) = '9'
THEN 'R'
END
END,
View 4 Replies
View Related
Mar 26, 2008
Hi all,
I'm running a transformation script that's taking decimal(18,10) data and trying to shoehorn it into a numeric(9,6). generally this works, as most of the data in the original table is not using anywhere near the precision it's capable of, but once in a while I run into one that does use it.
Is there any way to automagically reduce the precision so that i can cram the data into the destination table?
___________________________
Geek At Large
View 3 Replies
View Related
May 29, 2008
I'm trying, through the SQL 2005 Mgt Studio, to export a simple table in a delimited format. I'm selecting a double quote as the text qualifier. My expectations were that only text type fields would be exported with the double quotes an numerical fields would not have any quotes around them. SQL 2000 does this just fine, but 2005 is exporting all my text type and numeric fields with double quotes. Is this a change to SQL 2005 or am I doing something wrong.
Thanks for the help,
Tim
View 1 Replies
View Related
Jul 13, 2004
Can anyone tell me how I can strip certain chahrcters from a string
I know I can use replace, but i don't think this is appropriate for what I want to do
For example I have the string
declare @text varchar (100)
select @text = 'word1, word2 & word3'
if i do a replace on the string like this
select @text = 'replace(@text, ',', '')
select @text = 'replace(@text, '&', '')
I end up with the string
select @text = 'word1 word2 word3'
i.e. 2 spaces between word2 and word3
What i want the string to look like is :
select @text = 'word1 word2 word3'
Is there a way i can check for more than one space + characters ( / , &) in one go
many thanks
View 4 Replies
View Related
Feb 26, 2004
I don't know how the stars are attribuated
but I don't think I should have so many
It gives a false impression to new members
View 3 Replies
View Related
Sep 26, 2007
This algorithm can be used to strip out HTML tags too.
With reference to http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=89973
and http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=90000CREATE FUNCTIONdbo.fnParseRTF
(
@rtf VARCHAR(8000)
)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE@Stage TABLE
(
Chr CHAR(1),
Pos INT
)
INSERT@Stage
(
Chr,
Pos
)
SELECTSUBSTRING(@rtf, Number, 1),
Number
FROMmaster..spt_values
WHEREType = 'p'
AND SUBSTRING(@rtf, Number, 1) IN ('{', '}')
DECLARE@Pos1 INT,
@Pos2 INT
SELECT@Pos1 = MIN(Pos),
@Pos2 = MAX(Pos)
FROM@Stage
DELETE
FROM@Stage
WHEREPos IN (@Pos1, @Pos2)
WHILE 1 = 1
BEGIN
SELECT TOP 1@Pos1 = s1.Pos,
@Pos2 = s2.Pos
FROM@Stage AS s1
INNER JOIN@Stage AS s2 ON s2.Pos > s1.Pos
WHEREs1.Chr = '{'
AND s2.Chr = '}'
ORDER BYs2.Pos - s1.Pos
IF @@ROWCOUNT = 0
BREAK
DELETE
FROM@Stage
WHEREPos IN (@Pos1, @Pos2)
UPDATE@Stage
SETPos = Pos - @Pos2 + @Pos1 - 1
WHEREPos > @Pos2
SET @rtf = STUFF(@rtf, @Pos1, @Pos2 - @Pos1 + 1, '')
END
SET@Pos1 = PATINDEX('%cf[0123456789][0123456789 ]%', @rtf)
WHILE @Pos1 > 0
SELECT@Pos2 = CHARINDEX(' ', @rtf, @Pos1 + 1),
@rtf = STUFF(@rtf, @Pos1, @Pos2 - @Pos1 + 1, ''),
@Pos1 = PATINDEX('%cf[0123456789][0123456789 ]%', @rtf)
SELECT@rtf = REPLACE(@rtf, 'pard', ''),
@rtf = REPLACE(@rtf, 'par', ''),
@rtf = LEFT(@rtf, LEN(@rtf) - 1)
SELECT@rtf = REPLACE(@rtf, '0 ', ''),
@rtf = REPLACE(@rtf, ' ', '')
SELECT@rtf = STUFF(@rtf, 1, CHARINDEX(' ', @rtf), '')
RETURN@rtf
ENDE 12°55'05.25"
N 56°04'39.16"
View 10 Replies
View Related
Mar 26, 2004
I have a column of 5 comma-separated-value strings:
stringA, stringB, stringC, stringD, stringE
The strings are GUID's with the hyphen stripped and made all uppercase so they are completely random. I need to be able to remove any one of the strings including the comma, in a stored procedure and I am not sure how to accomplish this.
SELECT tickets
FROM users
WHERE CONTAINS (tickets, @ticket)
IF @@rowcount > 0
REMOVE STUFF HERE
SET @valid = 1
ELSE
SET @valid = 0
So if stringB gets passed in as @ticket then the new value in the column would be :
stringA, stringC, stringD, stringE
Any help is greatly appreciated.
Thank you
dave
View 9 Replies
View Related
Dec 4, 2000
I am trying to strip off 'XYZ' from column1 in table1 whenever it occurs
Any help appreciated
saad
View 4 Replies
View Related
Feb 17, 2004
I'm trying to find a way to strip text from a string. In the past (pre SQL Server) I would've used
LName: Left(NCBH!Name,InStr(1,NCBH!NAME,",",1)-1)
To strip the last name from a string like
Franks,George J
Apparently InStr is not a recognized function in SQL Server 2000. Or is it available but not in a view?
Any thoughts would be greatly appreciated.
View 2 Replies
View Related
Jan 11, 2002
I have a phone number string (416) 555-5555 in a table. I'd like to perform a search on the string so that the user is able to pass any number, and the query returns all phone numbers like it. What I'd like to do is to strip out the brackets and dashes and perform a like search.
View 4 Replies
View Related
Dec 14, 2007
Hi,
I use RS 2005 SP2.
I add a text item value " smth..."
No problem in preview, but export to pdf strip out whitespace characters and then my report in pdf like:
"smth..."
Is there a solution
View 15 Replies
View Related
Jan 18, 2005
I would like something I can do inline eg:
select convert(blahdatatype,a.datefield) as smallerdatefield
from
a
where a.datefield is a datetime. If a contains rows like:
datefield
---------------------
01/20/2005 22:17:23
08/23/2001 03:04:15
...
Then the SQL above returns:
smallerdatefield
---------------------
01/20/2005 00:00:00
08/23/2001 00:00:00
...
Is there any non-obnoxious way (eg: without have to result to using datepart a million times) to do this? For instance, Oracle provides a function called Trunc which does it, but I cannot find an SQL Server equivalent. Anyone? TIA!!!
View 9 Replies
View Related
Jan 16, 2006
I am not aware of this if it exists in MS SQL server. But I need to return results in alphabetic order ignoring "The" if it's the first word of a title...
so for example title "The Cliffhanger" would be returned along with other titles that start with letter C, but "The" also must be returned as part of the title, but just ignored while alphabetizing.
I'm sure that I'm not the first one to ever need this and don't want to re-invent the wheel, so if you have any ideas as to the best way to accomplish this, help me out.
Thanks in advance.
View 8 Replies
View Related
Mar 5, 2006
Hi All.
I have a coulmn that contains data in the following format.
COUNTRY/SATE/UNAME
What I would like to do is create another column in the table stripping out the COUNTRY/ and /UNAME
Example
Existing column value
US/NY/BLAH
New Column value
NY
View 3 Replies
View Related
Apr 23, 2008
stupid question - how do I strip the time portion from a date returned from now() or
Globals!ExecutionTime.
I MS either used consistent date functions across all platforms or include help in BOL for their VB functions in SSRS.....
View 5 Replies
View Related
Sep 1, 2006
the ssis expression language getdate() function returns the current date with the current time. i only need to get the current date, without the current time. for example: 9/1/2006
how would i construct the proper expression to return this value?
thanks in advance.
View 2 Replies
View Related
Apr 3, 2008
I am trying to do string scrubbing in a sql clr function, including removing certain HTML formatting. I would like to use HtmlDecode method, but it's my understanding that System.Web is not available for Sql Clr (without marking code unsafe - not an option for me as this is for an application we sell externally, and unsafe calls woudl not go over well with customers). Is there any class that IS supported for Sql Clr that exposes this functionality? Thanks.
View 10 Replies
View Related
Dec 24, 2007
if all I want is 12am of the date provided in a datetime column, is there a more elegant way of doing this than something like...
convert (datetime,
convert(varchar(2), month([time])) + '/' +
convert(varchar(2), day([time])) + '/' +
convert(varchar(4), year([time]))
)
View 1 Replies
View Related
Oct 16, 2007
Is there a way to strip off the time portion of a datetime datatype without changing the datatype?
I know I can convert it using CONVERT (NVARCHAR(10), dbo.tblPayments.PaymentDate, 101) but I need to keep it as a datetime datatype?
View 5 Replies
View Related
Jul 5, 2002
I need a script to find the position of the first non-numeric in a telno field and delete from that point onwards.
Example: 01208 12345 (Work) would become 01208 12345
Has anybody come across this before ?
TIA
Neil.
View 1 Replies
View Related
Nov 10, 2005
Hey everyone!
I'm doing an export from SQL into excel spreadsheet and then am going to clean out certain parts of the data with global search/replace. The problem is that the SQL data is full of special characters such as |'s and the little box looking characters.
How do I export without these characters?
I know its possible, I did it about 2 years ago and remember I did some crazy file conversion (make wk3 or something) but I no longer remember
Any help would be much appreciated!
Thanks,
Geoff
PS, attached is a screenshot of the data to give you an idea of what I'd like to strip!
View 1 Replies
View Related
Oct 1, 2007
Could this query be made more efficient?
It takes ages to run it. It strips of everything from an email address and keeps only the domain.
SUBSTRING(Mailaddress, CHARINDEX('@', Mailaddress) + 1, CHARINDEX('.', SUBSTRING(Mailaddress, CHARINDEX('@', Mailaddress) + 1, 100)) - 1) AS mail_domain
View 4 Replies
View Related
Oct 28, 2011
I have a table with a column that has html text. The column with html text is pretty big datatye varchar(max)... I wanted to check if any of you have any function that I can use to Strip out the HTML tags... I saw couple of version online, but it was running too slow..
This is the one I used: [URL] .....
View 9 Replies
View Related
Jul 27, 2015
If I have a string with the following values, I’d like to replace the non-numeric characters with a space.
Input
01234-987
012345678
01234 ext 65656
Tel 0123456
012345 898989
Output
01234 987
012345678
01234 65656
0123456
012345 898989
View 20 Replies
View Related