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.
| 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 1Column1ABCDEFGHJHKLMNOPQRSTUTable 2Column2 QRSTU LMNOP ABCD JHK EFGHNow, I wish to write a query where Table1.Column1 = Table2.Column2And 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 functionMadhivananFailing to plan is Planning to fail |
 |
|
|
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? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-01 : 09:58:01
|
| See if this workswhere Table1.Column1 = LTRIM(Table2.Column2)MadhivananFailing to plan is Planning to fail |
 |
|
|
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. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-04-01 : 10:32:27
|
| use LTRIM(RTRIM(Table2.Column2)) |
 |
|
|
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. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-04-01 : 10:36:42
|
np |
 |
|
|
|
|
|