473,666 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to remove leading spaces?

3 New Member
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 3260
DonRayner
489 Recognized Expert Contributor
Use the Ltrim function on your select statement IE

LTrim(column1 & " " & column2)
Oct 14 '08 #2
danield
3 New Member
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,568 Recognized Expert Moderator MVP
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
danield
3 New Member
Hello NeoPa,

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

danield
Oct 15 '08 #5
NeoPa
32,568 Recognized Expert Moderator MVP
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
2238
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. (Our legacy flat-file data uses fixed-length character expressions for data like contract numbers, I guess because in a 16-bit environment you'd run out of available numbers REALLY fast... right now our contract numbers are in the 700,000's,...
2
2840
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
1444
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 browser displays it crunches them in datagrid. Also i have update and delete buttons options in this datagrid. How can i display the leading spaces.? TIA
6
22876
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
2594
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): options { directory "/var/named"; listen-on { 192.168.11.22; 127.0.0.1; }; forwarders { 168.126.63.1; };
7
16463
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
4093
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
1427
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 at some point, but I don't think it ever went in. That would catch a common error introduced during maintenance. John Nagle
0
1148
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 being removed. I do not want leading spaces removed. How do I keep the leading spaces? There are no SQL Trims being used. <asp:TextBox ID="PoemText" TextMode="Multiline" Columns="90" Rows="25" runat="server" Text='<%#...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7386
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5664
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.