{"id":144,"date":"2017-11-23T03:11:28","date_gmt":"2017-11-23T03:11:28","guid":{"rendered":"http:\/\/lance.conryclan.com\/home\/?p=144"},"modified":"2017-11-23T03:11:28","modified_gmt":"2017-11-23T03:11:28","slug":"sorting-out-phone-number-hell","status":"publish","type":"post","link":"https:\/\/lance.conryclan.com\/home\/sorting-out-phone-number-hell\/","title":{"rendered":"Sorting out phone number hell"},"content":{"rendered":"<p><a href=\"http:\/\/lance.conryclan.com\/home\/wp-content\/uploads\/2017\/11\/phone-number-hell.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-145\" src=\"http:\/\/lance.conryclan.com\/home\/wp-content\/uploads\/2017\/11\/phone-number-hell.jpg\" alt=\"\" width=\"634\" height=\"319\" srcset=\"https:\/\/lance.conryclan.com\/home\/wp-content\/uploads\/2017\/11\/phone-number-hell.jpg 634w, https:\/\/lance.conryclan.com\/home\/wp-content\/uploads\/2017\/11\/phone-number-hell-300x151.jpg 300w\" sizes=\"auto, (max-width: 634px) 100vw, 634px\" \/><\/a><\/p>\n<p>In trying to consolidate my phone numbers, something broke, and the formatting of my numbers ended up broken.\u00a0 Augh.\u00a0 SQL Server to the rescue!<\/p>\n<p><!--more--><\/p>\n<p>I started out exporting all my various contact lists, and loading them into a SQL Server table.\u00a0 I then ran the following commands to make all my phone numbers valid again.\u00a0 Then exported to a CSV and imported back into google contacts.<\/p>\n<p style=\"padding-left: 30px;\">&#8211;remove all brackets<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;)&#8217;, &#8221;)<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;(&#8216;, &#8221;)<\/p>\n<p style=\"padding-left: 30px;\">&#8211;remove hyphens<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;-&#8216;, &#8221;)<\/p>\n<p style=\"padding-left: 30px;\">&#8211;replace leading 0011 with +<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = &#8216;+&#8217; + SUBSTRING([Phone 1 &#8211; Value], 5, LEN([Phone 1 &#8211; Value])-1) WHERE [Phone 1 &#8211; Value] LIKE &#8216;0011%&#8217;<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;::: 0011&#8217;, &#8216;::: +&#8217;)<\/p>\n<p style=\"padding-left: 30px;\">&#8211;remove leading 0s<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = SUBSTRING([Phone 1 &#8211; Value], 2, LEN([Phone 1 &#8211; Value])-1) WHERE [Phone 1 &#8211; Value] LIKE &#8216;0%&#8217;<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;::: 0&#8217;, &#8216;::: &#8216;)<\/p>\n<p style=\"padding-left: 30px;\">&#8211;add a plus where it&#8217;s missing on existing intl codes.<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = &#8216;+ &#8216; + [Phone 1 &#8211; Value] WHERE LEN([Phone 1 &#8211; Value]) &gt; 10 AND [Phone 1 &#8211; Value] LIKE &#8216;61%&#8217;<\/p>\n<p style=\"padding-left: 30px;\">&#8211;add the international code where required. Ignore local numbers (len &lt; 8)<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = &#8216;+61 &#8216; + [Phone 1 &#8211; Value] WHERE LEN([Phone 1 &#8211; Value]) &gt; 8 AND SUBSTRING([Phone 1 &#8211; Value], 1, 1) IN (&#8216;2&#8242;,&#8217;3&#8242;,&#8217;4&#8242;,&#8217;5&#8242;,&#8217;6&#8242;,&#8217;7&#8242;,&#8217;8&#8242;,&#8217;9&#8217;)<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;::: 2&#8217;, &#8216;::: +61 2&#8217;)<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;::: 3&#8217;, &#8216;::: +61 3&#8217;)<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;::: 4&#8217;, &#8216;::: +61 4&#8217;)<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;::: 5&#8217;, &#8216;::: +61 5&#8217;)<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;::: 6&#8217;, &#8216;::: +61 6&#8217;)<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;::: 7&#8217;, &#8216;::: +61 7&#8217;)<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;::: 8&#8217;, &#8216;::: +61 8&#8217;)<br \/>\nUPDATE google SET [Phone 1 &#8211; Value] = REPLACE([Phone 1 &#8211; Value], &#8216;::: 9&#8217;, &#8216;::: +61 9&#8217;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In trying to consolidate my phone numbers, something broke, and the formatting of my numbers ended up broken.\u00a0 Augh.\u00a0 SQL Server to the rescue!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-144","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/posts\/144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":3,"href":"https:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":148,"href":"https:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/posts\/144\/revisions\/148"}],"wp:attachment":[{"href":"https:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lance.conryclan.com\/home\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}