SQL Reporting format Phone Field

Posted on 2011-05-12
Last Modified: 2012-05-11
I have a stored procedure that returns a a string as 12345678900000.  I use this stored procedure in my SQL Server Report.  I want to display it is the format as (123) 456-7890.

I found the following wihch returns the value: (123) 456-7890000

=System.Text.RegularExpressions.Regex.Replace(Fields!VendorPhone.Value, "(\d{3})[ -.]*(\d{3})[ -.]*(\d{4})", "($1) $2-$3")

What can i change in this value to only display the first 10 digits?  In other words, how can I drop the 4 remaining zeros?

How can I do this in the SQL Report?  We're using SQL 2008
Question by:orther
    LVL 9

    Accepted Solution

    try this

    System.Text.RegularExpressions.Regex.Replace(Left(Fields!VendorPhone.Value,10), "(\d{3})[ -.]*(\d{3})[ -.]*(\d{4})", "($1) $2-$3")

    LVL 11

    Expert Comment

    or this:

    =left(System.Text.RegularExpressions.Regex.Replace(Fields!VendorPhone.Value, "(\d{3})[ -.]*(\d{3})[ -.]*(\d{4})", "($1) $2-$3"),10)

    Author Closing Comment

    Fast too

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. (htt…
    A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now