Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

572 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