insert space character in SQL

Posted on 2003-03-17
Medium Priority
Last Modified: 2008-02-01
I need to update Canadian zip codes fields in SQL SErver 2000. Canadian zip is 3 characters + space + 3 characters (7 characters in all).The problem is that there was no validation on our website until today and lots of users entered their zip codes as 6 characters, ie no space after 3rd character. As I am novice, I have no idea how to put space after 3rd character in those zipcodes which were entered without it and don't do anything to those which were entered correctly.
Any help will be greatly appreciated.
Thanks in advance!!!
I have only 50 points to award that questins, kindda not fair:-)
Question by:VadimVadim
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

chaos_hooi earned 200 total points
ID: 8156052
DECLARE @zip varchar(50)
SET @zip='123 456'
IF(CHARINDEX(' ', @zip, 1) <> 4)
 SET @zip=LEFT(@zip,3)+' '+ RIGHT(@zip,3)

Author Comment

ID: 8156068
Wow, that was really fast! Thanks a lot!!!

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

765 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