Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Format Zip Code Properly

Posted on November 11, 2013October 26, 2015 By David Kittell

Sometimes a zip code is presented in a database with all nine numbers in the same column that has only five numbers. This query below will assist in formatting the numbers properly.

SELECT CASE
		WHEN len(zip) = 10
			AND substring(zip, 6, 1) = '-'
			THEN zip
		WHEN len(zip) = 5
			THEN zip
		WHEN len(zip) = 9
			THEN left(zip, 5) + '-' + right(zip, 4)
		ELSE NULL
		END
FROM address
UPDATE address
SET zip = (
		CASE
			WHEN len(zip) = 10
				AND substring(zip, 6, 1) = '-'
				THEN zip
			WHEN len(zip) = 5
				THEN zip
			WHEN len(zip) = 9
				THEN left(zip, 5) + '-' + right(zip, 4)
			ELSE NULL
			END
		)

Source: http://forums.sqlmag.com/forums/aft/77318

Originally Posted on November 11, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code MSSQL SQL

Post navigation

Previous post
Next post

Related Posts

Flash Video

Posted on September 3, 2013October 26, 2015

<script language="JavaScript" type="text/javascript"> // <![CDATA[ var fo = new FlashObject("../flash/videoPlayer.swf", "foo", "455","400", "8.0.22", "#ffffff", true); fo.addParam("wmode", "transparent"); fo.addParam("quality","high"); fo.addParam("align","middle"); fo.addParam("salign",""); fo.addParam("scale","noscale"); fo.addParam("allowScriptAccess","sameDomain"); //flash vars that need to be passed into the flash movie … fo.addVariable(‘userId’, ‘public’); fo.addVariable(‘videoId’, ‘HealthClips/hc_ca_00053_en’); fo.addVariable(‘skinName’,’../flash/haloSkin_1.swf’); fo.addVariable(‘bufferTime’, ‘3’); fo.addVariable(‘autoRewind’, ‘true’); fo.addVariable("autoPlay", "true"); fo.addVariable(‘streamId’, ‘HealthClips/hc_ca_00053_en’); fo.write("flashcontent"); // ]]>…

Read More

PHP WordPress – Check If MultiSite From CLI

Posted on November 3, 2015

require(dirname(__DIR__) . ‘/html/wp-config.php’); if(defined(‘WP_ALLOW_MULTISITE’)) { if (constant("WP_ALLOW_MULTISITE") == true) { echo "\nThis site is MultiSite\n"; } else { echo "\nThis site is not MultiSite\n"; } } else { echo "\nThis site is not MultiSite\n"; } All information on this site is shared with the intention to help. Before any source…

Read More

Android Contacts – Remove Websites

Posted on March 2, 2014October 26, 2015

DELETE FROM data WHERE mimetype_id IN ( SELECT _id FROM mimetypes WHERE mimetype LIKE "%web%" ) AND data1 LIKE ‘%facebook.com%’; Originally Posted on March 2, 2014Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code or program is…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories
  • Raspberry Pi - Remove Default Apps
  • PowerShell - Change Windows CD/DVD Drive Letter
©2025 David Kittell | WordPress Theme by SuperbThemes