473,411 Members | 1,899 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,411 software developers and data experts.

How to remove leading spaces?

Hello All,

I have a query that I use to create another table:

Expand|Select|Wrap|Line Numbers
  1. SELECT    column1 & " " & column2 INTO table2
  2. FROM        table1
  3.  
The problem is that sometimes there is no value in column1 and then the new entry in table2 is 'space' and then column2. For example if first column has '1' and second column has '2', the new record in the table2 would be '1 2' but if another row has nothing in the column 1 and then '3' in the column2, resulting row in table to would be ' 3'. How to remove the leading space? Or how to prevent the empty space from being created?

Thank you for your time.

danield
Oct 14 '08 #1
5 3242
DonRayner
489 Expert 256MB
Use the Ltrim function on your select statement IE

LTrim(column1 & " " & column2)
Oct 14 '08 #2
Use the Ltrim function on your select statement IE

LTrim(column1 & " " & column2)
Hello DonRayner,

Thank you very much. Ltrim does exactly what I need :)

danield
Oct 14 '08 #3
NeoPa
32,556 Expert Mod 16PB
You can use the Trim() function, but if you are wanting to reflect the actual values where one column is mandatory but the other isn't (EG Name fields where surname is mandatory but the GivenName is optional) then you can make use of the the difference between & and + as string concatenators.

A & B = AB but if B is Null then = A
A + B = AB but if either is Null then = Null

So [GivenName] + ' ' & [Surname] gives the correct result whichever. If [GivenName] is null then the ' ' is reduced to null too by the +.
Oct 14 '08 #4
Hello NeoPa,

Thank you very much for this information. I will try it out.

danield
Oct 15 '08 #5
NeoPa
32,556 Expert Mod 16PB
No worries :) We're here to help.

Welcome to Bytes!
Oct 16 '08 #6

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

Similar topics

0
by: Ellen K. | last post by:
In a previous post I mentioned having a problem getting leading spaces to be written to SQL Server using OPENXML. They showed up fine in my XML documents if I printed them, but not in my database....
2
by: BobM | last post by:
I have two strings that I would like to compare. To guarantee the compare is not affected by trailing spaces, I would like to remove them. Will this do: MyTextBox.text.ToString().Trim()?
3
by: SKG | last post by:
i have leading spaces in my database fields. When they appear in the datagrid in browser, they seem to be truncated. I did view source in browser and found that there are indeed spaces but when...
6
by: Paul | last post by:
Hi just wondering if there is an easy way to remove spaces in a string, tried the trim method but think it is only for leading or trailing spaces. thanks -- Paul G Software engineer.
36
by: Roman Mashak | last post by:
Hello, All! I implemented simple program to eliminate entry from the file having the following structure (actually it's config file of 'named' DNS package for those who care and know): ...
7
by: Bosconian | last post by:
I know that str.replace(/^\s+|\s+$/g,''); will trim a string of space, but what about removing extra spaces from the middle? Where "hello world"
34
by: Registered User | last post by:
Hi experts, I'm trying to write a program that replaces two or more consecutive blanks in a string by a single blank. Here's what I did: #include <stdio.h> #include <string.h> #define MAX 80
4
by: John Nagle | last post by:
One can argue over tab vs. space indentation, but mixing the two is just wrong. Why not have CPython report an error if a file has both leading tabs and leading spaces? I know that was proposed...
0
by: markpringle | last post by:
I am using a very simple multiline textbox (below) to capture text (poems). Many poems require formatting of the first line by including leading spaces. However, on submit, the leading spaces are...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.