473,378 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Adding a space in between the data values

Hi,
I want to add a space between postal code in my database but don't know how to accomplish it.
We have postal code format N1H8L5 or N1H 8L5 (note: a space between the middle of six characters. We have both kind of formats entered in our database.
I want to change them all to the the one format with the sapce in between.
How I can change those without space in between to the desired format.
Thanks for your help.
Syed
Mar 17 '08 #1
7 4331
ronverdonk
4,258 Expert 4TB
Best I can come up now is, assuming pc is the table column to be changed
Expand|Select|Wrap|Line Numbers
  1. update table_name set pc=if(substring(pc,4,1)=' ',pc, concat(substr(pc,1,3),space(1),substring(pc,4,3)));
You can expand it by also cheking the length of the 'pc' field.

Ronald
Mar 17 '08 #2
Hi Ronald,
You are a great help. Thanks a lot. It did work for me and now I have all the postal codes with a space in between.
Thanks again for your help.

Syed
Mar 17 '08 #3
ronverdonk
4,258 Expert 4TB
Glad I could help you out. See ya!

Ronald
Mar 17 '08 #4
Hi Ronald,
I hope I am not asking too much but would you please elaborate that code a little bit for me so I can understan how it did work. Its just part of my learning process.
Thanks again.
Syed
Mar 17 '08 #5
ronverdonk
4,258 Expert 4TB
Hi Ronald,
I hope I am not asking too much but would you please elaborate that code a little bit for me so I can understan how it did work. Its just part of my learning process.
Thanks again.
Syed
Expand|Select|Wrap|Line Numbers
  1. SET pc=IF(SUBSTRING(pc,4,1)=' ',pc, CONCAT(substr(pc,1,3),SPACE(1),SUBSTRING(pc,4,3))); 
the IF has the following syntax: IF(condition, result, result)
This returns the second argument result if condition (the first argument) is met, and the third argument is not.

In this statement meaning:
Update column pc in table with the condition that, when position 4 in the pc string is a blank, the content of pc is returned.
When the char in position 4 of pc is not a blank, then return a string made up of the first 3 chars of pc plus a blank plus the last 3 chars from pc.

Got it?

Ronald
Mar 17 '08 #6
Thanks again Ronald,
So nice of you taking time to explain that to me.

Take care,
Syed
Mar 18 '08 #7
ronverdonk
4,258 Expert 4TB
At your service. See you.

Ronald
Mar 18 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Sunny K | last post by:
Hi guys, I have a field in my DB called EventDate as a DateTime field, therefore it holds both the date and time together like this: '2004-10-14 08:42:57.000'. I need to add together all the...
6
by: 6thirty | last post by:
Hi, I've created a stocktaking database using Access XP. This is indexed by two fields - part number and shelf location. I am currently inputting all the data via a form. When I have entered a...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
47
by: Pierre Barbier de Reuille | last post by:
Please, note that I am entirely open for every points on this proposal (which I do not dare yet to call PEP). Abstract ======== This proposal suggests to add symbols into Python. Symbols...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
3
by: Peter Michaux | last post by:
Hi, These first three links say that when reading document.cookie the name-value pairs are separated by semicolons and they show examples like "name=value;expires=date" where there is clearly...
4
by: ttest | last post by:
Hello, I'm working on an image processing project using the Python Imaging Library along with numpy. Right now, I'm trying to build a speedy script for converting whole images between the RGB...
10
by: Guillermo_Lopez | last post by:
Hello All, I am using VBA in access to perform some calculations. There is a particular sumation that is wrong (barely). this code is withing a loop. TDist = TDist + TempDist Both TDist...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.