Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Remove spaces from the beginning of the rows

Author  Topic 

notes4we
Yak Posting Veteran

90 Posts

Posted - 2009-04-01 : 09:30:40
I have a two tables with one column as below:

Table 1
Column1
ABCD
EFGH
JHK
LMNOP
QRSTU

Table 2
Column2
QRSTU
LMNOP
ABCD
JHK
EFGH


Now, I wish to write a query where Table1.Column1 = Table2.Column2
And I expect to get all the results back, like ABCD for ABCD and so on and so forth.

Now the issue is the additional spaces that are there in the Table2, Column2. Can anyone of you please help me with the sql code that can help me to eliminate those extra spaces from the left and allow me to get the desired results.

Thanks in advance.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-01 : 09:35:51
What do you mean by additional spaces?
Use ltrim function

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

notes4we
Yak Posting Veteran

90 Posts

Posted - 2009-04-01 : 09:55:02
Yes, I know about LTRIM function, but I am not sure how will I be able to do it for all the rows that are in the column?

Can anyone please tell me the syntax for the same?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-01 : 09:58:01
See if this works

where Table1.Column1 = LTRIM(Table2.Column2)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

notes4we
Yak Posting Veteran

90 Posts

Posted - 2009-04-01 : 10:27:49
Yes, LTRIM works, but when I do the same for TRIM, it does not work. What if I want to move the extra spaces from both the ends: left and right?

Thank you for your assistance.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-04-01 : 10:32:27
use LTRIM(RTRIM(Table2.Column2))
Go to Top of Page

notes4we
Yak Posting Veteran

90 Posts

Posted - 2009-04-01 : 10:35:59
quote:
Originally posted by vijayisonly

use LTRIM(RTRIM(Table2.Column2))




Yes, that worked. It was simple, but new for me.
Thank you for your prompt reply.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-04-01 : 10:36:42
np
Go to Top of Page
   

- Advertisement -