Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Stripping input mask from phone numbers
Hello, I have this Access 2K query that I need to re-create in MS SQL
Server 2000, so I'm using the Query Analyzer to test it.

One of the Access fields stores the home phone number.  In the Access
query, if the phone number is null, it fills it up with zeroes
"000000000." If the phone has an input mask, it only gets the 9 numbers
(area code included) and if the phone number's good (all numbers) then
it leaves it alone.  That Access query is using immediate ifs to
accomplish that task.

Does anyone have any idea how to copy this behavior into SQL Server
2000?  I've using the CASE statement but so far my code is not correct.
I get stuck in the input mask.  This is the Access code:

HomePhone:
IIf(IsNull([HomePhone]),"0000000000",IIf(Left([HomePhone],1)="(",Rig
ht(Left(& #91;Homephone],4),3)

& Right(Left(& #91;Homephone],9),3)
 & Right([HomePhone],4),[HomePhone
]))

Thanks for all your help.

JR.


Report this thread to moderator Post Follow-up to this message
Old Post
ILCSP@NETZERO.NET
03-29-06 01:26 AM


Re: Stripping input mask from phone numbers
(ILCSP@NETZERO.NET)  writes:
> HomePhone:
>
IIf(IsNull([HomePhone]),"0000000000",IIf(Left([HomePhone],1)="(",Rig
ht(Left(
& #91;Homephone],4),3)

> & Right(Left(& #91;Homephone],9),3)
 & Right([HomePhone],4),[HomePho
ne]))
>

CASE WHEN HomePhone IS NULL
THEN '0000000000'
WHEN  substring(HomePhone,
 1, 1) = '('
THEN  substring(HomePhone,
 2, 3) +  substring(HomePhone,
 6, 3) +
 substring(HomePhone,
 10, 4)
ELSE HomePhone
END

I don't know exactly what the Left and Right functions do, so I had
to make a guess for substring.

A better approact is probably

 replace(replace(repl
ace(HomePhone, '(', ''), ')', ''), '-', '')



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Report this thread to moderator Post Follow-up to this message
Old Post
Erland Sommarskog
03-29-06 01:26 AM


Re: Stripping input mask from phone numbers
Thanks Er.  That was exactly what I was looking for.  Both of them work
beautifully.


Report this thread to moderator Post Follow-up to this message
Old Post
ILCSP@NETZERO.NET
03-29-06 01:26 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 07:47 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006