Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Format Phone Numbers to NNN-NN-NNNN

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Format Phone Numbers to NNN-NN-NNNN

    I have about 8,000 phone numbers in a table. Some were entered in this format "301-555-1212", and some are like this "3015551212." I'd like to correct them all to the format of "301-555-1212," so I tried running an operation of:
    left(Phone,3) + "-" + substr(Phone,4,3) + "-" + substr(Phone,7,4)

    That works if the numbers were entered in the format of "3015551212," but they are already in the correct format of "301-555-1212," it causes them to change to this: "301--55-5-12,"

    Is there a way to run the operation and only have it effect numbers that were entered incorrectly?​
    Attached Files
    Sergeant Richard Hartnett
    Hyattsville City Police Department
    Maryland

    #2
    Hi Rich,

    Try stuff(stuff(remspecial(phone),7,0,"-"),4,0,"-")
    It will also do the job for the people the like to use periods and/or spaces.
    Gregg
    https://paiza.io is a great site to test and share sql code

    Comment


      #3
      Thanks Madtowng. I tried that expression, but it took 3015551212 and turned it into 301555-1212
      Sergeant Richard Hartnett
      Hyattsville City Police Department
      Maryland

      Comment


        #4
        Looks like it's missing one of the stuff functions.

        Here's a more complete answer, as well as several tries.
        Capture.png

        Code:
        function phoneFormatter as C (pn as C)
            return  stuff(stuff(remspecial(pn),7,0,"-"),4,0,"-")
        end function​
        Gregg
        https://paiza.io is a great site to test and share sql code

        Comment


          #5
          Just a thought.
          if you remove all previous formatting and then apply your code it should work Back it up first!
          See our Hybrid Option here;
          https://hybridapps.example-software.com/


          Apologies to anyone I haven't managed to upset yet.
          You are held in a queue and I will get to you soon.

          Comment


            #6
            Ted Giles It's easy to see you looked at the code.
            Gregg
            https://paiza.io is a great site to test and share sql code

            Comment


              #7
              That was it, Greg. The extra command "Stuff" at the beginning of the expression was the issue and now it works great!

              Thanks everyone.
              Sergeant Richard Hartnett
              Hyattsville City Police Department
              Maryland

              Comment


                #8
                Glad to help Rich.
                Gregg
                https://paiza.io is a great site to test and share sql code

                Comment


                  #9
                  Nice bit of code Gregg.
                  Are you taking over from Stan?
                  I just popped a comment from my phone as a Q&D solution.
                  ​​​​Apologies I didn't pay more attention. (But it would have worked)
                  See our Hybrid Option here;
                  https://hybridapps.example-software.com/


                  Apologies to anyone I haven't managed to upset yet.
                  You are held in a queue and I will get to you soon.

                  Comment


                    #10
                    I'd love to say yes, but until I solve my text overload issue I think it's
                    best I stick with things I understand.
                    Gregg
                    https://paiza.io is a great site to test and share sql code

                    Comment


                      #11
                      LOL!
                      I have tried dictating stuff via my car to the forum ( it has voice recognition and voice acivation and we have conversations) to save texting. Boy, have I had issues!
                      "Sorry officer!"
                      See our Hybrid Option here;
                      https://hybridapps.example-software.com/


                      Apologies to anyone I haven't managed to upset yet.
                      You are held in a queue and I will get to you soon.

                      Comment


                        #12
                        Yes.

                        Undo any formatting with remspecial() then apply the formatting you want.

                        You should check the length of the data with len(alltrim())

                        Did you intend for your title to be NNN-NN-NNNN or NNN-NNN-NNNN?



                        Al Buchholz
                        Bookwood Systems, LTD
                        Weekly QReportBuilder Webinars Thursday 1 pm CST

                        Occam's Razor - KISS
                        Normalize till it hurts - De-normalize till it works.
                        Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                        When we triage a problem it is much easier to read sample systems than to read a mind.
                        "Make it as simple as possible, but not simpler."
                        Albert Einstein

                        http://www.iadn.com/images/media/iadn_member.png

                        Comment


                          #13
                          We have about 15,000 phone numbers in our tables and we are constantly getting additions and updates from our clients in csv and excel, so we found it is faster to do the check in MySQL. We also need the option for adding a leading 1 and/or dashes. If anybody is interested, here is a Stored Function that will handle that

                          Input parameters are pPhoneIn varchar(24), pLeading1 TINYINT(1), pDashes TINYINT(1)

                          BEGIN
                          /* Function FixPhone
                          This routine strips all non numeric characters from a number and optionally inserts our standard characters
                          Setting pLeading1 = 1 results in leading 1. setting pDashes = 1 results in dash separators.
                          Otherwise just the number. Includes error checking.
                          If the number cannot be converted, it is kept as is. */

                          DECLARE vPhoneIn, vPhoneWork, vPhoneOut, vResult VARCHAR(24);
                          DECLARE vLatinNumber VARCHAR(24);
                          DECLARE vCharLength, vCount TINYINT(3) UNSIGNED;
                          DECLARE vThisChar, vLeadingChar CHAR(1);
                          DECLARE flag_done, flag_error TINYINT(1) UNSIGNED;
                          # Initialize
                          SET flag_done = 0, flag_error = 0, vLeadingChar = '';
                          SET vPhoneIn = TRIM(pPhoneIn);
                          SET vPhoneOut ='', vPhoneWork = '';
                          # Handle NULL and blank
                          IF ISNULL(vPhoneIn) THEN
                          SET vPhoneOut = NULL;
                          SET flag_done = 1;
                          ELSEIF vPhoneIn = '' THEN
                          SET vPhoneOut = '';
                          SET flag_done = 1;
                          END IF;
                          # Convert to latin1 colation to get accurate count of number of characters
                          IF flag_done = 0 THEN
                          SET vLatinNumber = CONVERT(vPhoneIn USING latin1);
                          SET vCharLength = CHAR_LENGTH(vLatinNumber);
                          # strip out any non numeric characters
                          SET vCount = 1;
                          WHILE vCount <= vCharLength DO
                          SET vThisChar = MID(vLatinNumber,vCount,1);
                          IF vThisChar IN ('1','2','3','4','5','6','7','8','9','0') THEN
                          SET vPhoneWork = concat(vPhoneWork,vThisChar);
                          END IF;
                          SET vCount = vCount + 1;
                          END WHILE;
                          SET vCharLength = CHAR_LENGTH(vPhoneWork);
                          SET vLeadingChar = LEFT(vPhoneWork,1);

                          # Check for leading 1
                          IF pLeading1 = 0 THEN
                          IF vCharLength = 10 AND vLeadingChar != '1' THEN
                          SET vPhoneOut = vPhoneWork;
                          ELSEIF vCharLength = 11 AND vLeadingChar = '1' THEN
                          SET vPhoneOut = RIGHT(vPhoneWork,10);
                          ELSE
                          SET flag_error = 1;
                          SET vPhoneOut = pPhoneIn;
                          END IF;
                          ELSEIF pLeading1 = 1 THEN
                          IF vCharLength = 11 AND vLeadingChar = '1' THEN
                          SET vPhoneOut = vPhoneWork;
                          ELSEIF vCharLength = 10 AND vLeadingChar <> '1' THEN
                          SET vPhoneOut = CONCAT('1',vPhoneWork);
                          ELSE
                          SET flag_error = 1;
                          SET vPhoneOut = pPhoneIn;
                          END IF;
                          END IF;

                          # Insert dashes if needed
                          IF flag_error = 0 AND pDashes = 1 THEN
                          IF LEFT(vPhoneOut,1) = '1' THEN
                          SET vPhoneOut = CONCAT(LEFT(vPhoneOut,4),"-",MID(vPhoneOut,5,3),"-",RIGHT(vPhoneOut,4));
                          ELSE
                          SET vPhoneOut = CONCAT(LEFT(vPhoneOut,3),"-",MID(vPhoneOut,4,3),"-",RIGHT(vPhoneOut,4));
                          END IF;
                          END IF;
                          END IF;
                          SET vResult = vPhoneOut;
                          RETURN vResult;
                          END​
                          Pat Bremkamp
                          MindKicks Consulting

                          Comment


                            #14
                            Pat Bremkamp How did you get the data from spreadsheets into mysql ?
                            Gregg
                            https://paiza.io is a great site to test and share sql code

                            Comment


                              #15
                              Isn't it the simple Import/Export function?
                              See our Hybrid Option here;
                              https://hybridapps.example-software.com/


                              Apologies to anyone I haven't managed to upset yet.
                              You are held in a queue and I will get to you soon.

                              Comment

                              Working...
                              X